Javascript AJAX代码未运行
我多次查看此代码,但不知道问题出在哪里:Javascript AJAX代码未运行,javascript,php,html,xml,http,Javascript,Php,Html,Xml,Http,我多次查看此代码,但不知道问题出在哪里: 函数加载(){ if(window.XMLHttpRequest){ xmlhttp=新的XMLHttpRequest(); }否则{ xmlhttp=newActiveXObject('Microsoft.xmlhttp'); } xmlhttp.onreadystatechange=函数(){ if(xmlhttp.readyState==4&&xmlhttp.status==200){ document.getElementById('adiv
函数加载(){
if(window.XMLHttpRequest){
xmlhttp=新的XMLHttpRequest();
}否则{
xmlhttp=newActiveXObject('Microsoft.xmlhttp');
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById('adiv').innerHTML=xmlhttp.responseText;
}
}
open('GET','inculde.inc.php',true);
xmlhttp.send();
}
我在任何浏览器中运行它,但什么也没发生 提供信息!您的web服务器应该返回什么?您没有使用'var'关键字include.inc.php声明变量,只是在phpw中使用了简单的echo在“inculde.inc.php”中有什么?您是否检查了控制台中的错误?也许函数甚至找不到php文件!您可以添加错误消息或结果的简要说明(例如:空页),以便更容易跟踪问题。
<html>
<head>
<script type = "text/javascript">
function load(){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
document.getElementById('adiv').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','inculde.inc.php',true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="submit" onclick = "load();">
<div id ="adiv"></div>
</body>
</html>