gpt4 book ai didi

javascript - 简单的ajax无法工作,可能是语法错误

转载 作者:行者123 更新时间:2023-11-28 14:05:14 24 4
gpt4 key购买 nike

window.onload = function(){
testAjax();
}

var testAjax = function(){
var request = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
request.onreadystatechange = function(){
if (request.readyState == 4){
// Server is done
try{
var p = document.getElementById['a'];
p.innerHTML = request.responseText;
//document.write(request.responseText);
}
catch(e){
document.write('More Epic Fail');
}
}
}
request.open('GET','updatethumbs.php',true);
request.send(null);
}

最佳答案

快速浏览后:

var p = document.getElementById['a'];

应该是:

var p = document.getElementById('a');

关于javascript - 简单的ajax无法工作,可能是语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1871717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com