新手继续问个AJAX请求问题
我的AJAX请求在IE上正常,能局部刷新了,在google和火狐上请求没发送到WEB服务器上.
function loadXMLDoc( )
{
url = "~sid="+Math.random();
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Mozilla, IE7, etc.
xmlhttp=new XMLHttpRequest();
alert("window-XMLHttpRequest");
}
else if (window.ActiveXObject)
{
try
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
alert("Msxml2-XMLHTTP");
}
catch (e)
{
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
alert("Microsoft-XMLHTTP");
}
catch (e)
{
alert("NOT-HOST");
}
}
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
if(time_out)
setTimeout("loadXMLDoc( )",time_out);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
str = xmlhttp.responseText;
document.getElementById('demoajx1').value='Fresh...';
time_out =1000*parseInt(canshu[0])+1000;
}
else
{
alert("Problem retrieving data:" +'&'+xmlhttp.status+'&'+ xmlhttp.statusText);
}
}
}
alert 得到window.XMLHttpRequest
xmlhttp.status = 0 而且AJAX请求没发送到WEB服务器(没接收到数据)
是什么原因呢?
------解决方案--------------------url = "
~sid=" + Math.random();
有这种url??
你代码没贴全吧,xmlhttp那样申明是局部变量,