我的Ajax代码不起作用。

时间:2017-03-14 22:04:40

标签: ajax

"的text.txt"与html文件位于同一文件夹中,因此不应该出现问题。我想将h4标题更改为文本文件中的文本

function load_doc(){
    var xhttp = new XMLHttpRequest();
    xttp.onreadystatechange = function(){
        if (this.readyState == 4 && this.status == 200){
            document.getElementById("ajax_example").innerHTML = this.responseText;
        }
    };
    xhttp.open("GET","text.txt",true);
    xhttp.send();
}


<div id="ajax_example">
    <h4>Request Object</h4>
    <button type="button" onclick="load_doc()">Change Text</button>
</div>

1 个答案:

答案 0 :(得分:0)

您是否尝试过完整路径规范?

之类的东西
xhttp.open('GET', 'file:///home/user/text.txt', true);
相关问题