<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文件?
请张贴的代码,而不是代码的图像为我工作。你也有任何控制台中的错误? – tommyO
也从你的图像看起来像'callFunc'被调用,但没有定义。 – tommyO
您的浏览器可能不允许通过XHR加载本地文件。 –