我正在尝试使我的第一个ajax示例在我的MAMP上运行。我的ajax.html看起来像:
我的ajax.js看起来像:
函数ajax()
{
>> var xmlhttp;
如果(window.XMLHttpRequest)
{// IE7 +,Firefox,Chrome,Opera,Safari的代码
xmlhttp = new XMLHttpRequest();
}
其他
{// IE6,IE5的代码
xmlhttp = new ActiveXObject(“ Microsoft.XMLHTTP”);
}
xmlhttp.open(“ GET”,“ http:// localhost:8888 / ajax.php”,true);
xmlhttp.send();
xmlhttp.onreadystatechange = function()
{
如果(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById(“ test”)。innerHTML = xmlhttp.responseText;
}
}
}
我的ajax.php看起来像:
回声“你好世界”;
我从萤火虫中检测到响应标头:
响应标头
连接Keep-Alive
内容长度11
Content-Type text / html
日期2012年11月5日星期一18:57:46 GMT
Keep-Alive超时= 5,最大值= 99
服务器Apache / 2.2.22(Unix)mod_ssl / 2.2 .22 OpenSSL / 0.9.8r DAV / 2 PHP /
5.4.4
X-Pad避免浏览器错误
X-Powered-By PHP / 5.4.4
但响应文本中没有任何变化,我的html中也没有任何变化。
有人可以帮我吗?
谢谢!