为什么《Ajax基础教程》的例子在IE正常运行,而Firefox和Opera都不能执行?
就是第2章的2.3节的例子,在ie下测试通过,一切正常,而在Firefox和Opera下没有任何反映,本应alert()返回的xmlhttp.responseText,但是只有IE弹出了报警框,其余2个都没有反映,我的firefox安装了dominspector,一切正常也没有报错,javascript控制台也看不到错误,但确实没有反映,请高手指点下?
例子源码:
var xmlhttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}
function startRequest()
{
createXMLHttpRequest();
xmlhttp.onreadystatechange = handleStateChange;
xmlhttp.open('GET','SimpleResponse.xml?temp'+ Math.random(),true);
xmlhttp.send(null);
}
function handleStateChange()
{
if (xmlhttp.readystate == 4)
{
if (xmlhttp.status == 200)
{
alert ("服务器回应:" + xmlhttp.responseText);
}
}
}
在一个html里包含上面的源码,点击激活startRequest()函数,但是只有ie产生了效果