0
"text.txt"は、問題ではないはずのhtmlファイルと同じフォルダにあります。 h4ヘッダーをテキストファイル内のテキストに変更したい私のAjaxコードが機能していません。
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>
よう 何かがあなたが動作しませんでした – Onix
何かを得るかどうかを確認するためにxhttp.responseTextをCONSOLE.LOGしてみてください。つまり、document.getElementById( "ajax_example")。innerHTML = console.log(xhttp.responseText) –