+ -
当前位置:首页 → 问答吧 → 在IE下正常,在firefox下第一次打开返回空值,要刷新一下后就正常了

在IE下正常,在firefox下第一次打开返回空值,要刷新一下后就正常了

时间:2011-04-10

来源:互联网

function showshi(data){
//alert('aadsf');
//XMLHttpReq.setRequestHeader("Content-Type","gb2312");
xmlhttp.open("GET","showcity.php?t="+Math.random()+"&sheng="+data,true);
xmlhttp.send(null);
document.getElementById('shi').innerHTML = process_request;//显示状态
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status){
alert(xmlhttp.responseText);
//var responseTexts = xmlhttp.responseText;
//document.getElementById('shi').innerHTML=responseTexts;
}
else{
alert('sdfsdf');
}
}
}
}

在firefox下第一次打开页面alert(xmlhttp.responseText);是空;刷新一下后就每次都正常了;在IE 不存在这个问题,好奇怪,不知道原因,求救。。。。。。

作者: dqfxptom   发布时间: 2011-04-10

是不是数据还没有加载完,你就对数据进行操作了?

作者: y_h_t   发布时间: 2011-04-11

function showshi(data){
//alert('aadsf');
//XMLHttpReq.setRequestHeader("Content-Type","gb2312");
document.getElementById('shi').innerHTML = process_request;//显示状态
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status){
alert(xmlhttp.responseText);
//var responseTexts = xmlhttp.responseText;
//document.getElementById('shi').innerHTML=responseTexts;
}
else{
alert('sdfsdf');
}
}
}

xmlhttp.open("GET","showcity.php?t="+Math.random()+"&sheng="+data,true);
xmlhttp.send(null);
}

回调函数要设置在上面。把顺序调整一下

作者: licip   发布时间: 2011-04-11