로컬에서 html에서 html 파일 인클루드

로컬에서 html에서 html 파일 인클루드

QA

로컬에서 html에서 html 파일 인클루드

본문

로컬에서 html에서 html 파일 인클루드

방법이있을까요?

$("#header").load("header.html")

이방법으로 하려는데;

 

blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

이 에러메시지가 나와서요.

 

이 질문에 댓글 쓰기 :

답변 3

이렇게 해보심이.. 

 


<script>
    //includeHTML() 함수
    function includeHTML() {
        var z, i, elmnt, file, xhttp;
        /*loop through a collection of all HTML elements:*/
        z = document.getElementsByTagName("*");
        for (i = 0; i < z.length; i++) {
            elmnt = z[i];
            /*search for elements with a certain atrribute:*/
            file = elmnt.getAttribute("html-include");
            if (file) {
                /*make an HTTP request using the attribute value as the file name:*/
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                    if (this.readyState == 4) {
                        if (this.status == 200) { elmnt.innerHTML = this.responseText; }
                        if (this.status == 404) { elmnt.innerHTML = "Page not found."; }
                        /*remove the attribute, and call this function once more:*/
                        elmnt.removeAttribute("html-include");
                        includeHTML();
                    }
                }
                xhttp.open("GET", file, true);
                xhttp.send();
                /*exit the function:*/
                return;
            }
        }
    };
     $(document).ready(function() {
        //includeHTML() 함수 실행
        includeHTML();
     });
</script>
<!-- 인클루드해서 넣을 HTML 주소를 html-include=""에 넣음 -->
<div id="header" html-include="header.html"></div>

아 동일한 이유겠네요;; 서버에서 실행해야 되는거겠네요;;
혹시 에디터플러스를 사용하시면 일단 테스트는 가능할 거 같은데요.
편집창에서 Ctrl + B 누르시면 에디터플러스 창내에서 브라우저가 열려서 화면은 볼 수 있을거 같아요.

오류내용은 외부도메인의 값은 불러올 수 없다는 뜻입니다.

양 쪽 다 서버 설정이 가능하다면, 허용도메인을 설정하시거나

지금처럼 하시려면 같은 도메인내에서 사용하셔야 합니다

내컴퓨터에 Autoset 등 APM설치 프로그램으로 서버 구축후

ajax관련 함수 - 여기서는 load() - 를 사용하는 경우 그런 문제가 생기더군요.

실제 서버에 올려 테스트해 보시죠.

답변을 작성하시기 전에 로그인 해주세요.
전체 123,665 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT