<div id="new"></div>
<button id="btn" onclick="changeContent('C:\Users\MarshMellow\Desktop\whatever.txt', newFunc)">Click Here!!</button>
<script type="text/javascript">
function changeContent(url,callFunc) {
var xhttp;`declaration'
xhttp.onreadystatechange= function() {
if(this.readyState == 4 && this.status == 200) {
callFunc(this);
}
};
xhttp.open("GET","C:\Users\MarshMellow\Desktop\whatever.txt",true);
xhttp.send();
}
function newFunc(xhttp) {`Function call`
document.getElementById("new").innerHTML=xhttp.responseText;
}
여전히 출력이 없습니다. AJAX 호출이 제대로 작동하지 않는 것 같습니다.어떻게 AJAX 호출을 사용하여 텍스트 또는 XML 파일에 액세스 할 수 있습니까?
The XMLHttpRequest Object이 파일을 사용하는 나를 위해 작동합니다. 또한 콘솔에 오류가 있습니까? – tommyO
또한 이미지에서'callFunc'가 호출되었지만 정의되지 않은 것처럼 보입니다. – tommyO
귀하의 브라우저는 아마도 XHR을 통해 로컬 파일을로드하는 것을 허용하지 않을 것입니다. –