AJAX 在IE中总是提示没有对象 但在Firefox却没问题 - Web 开发 / Ajax
我是想使用AJAX动态从数据库中读取内容,当鼠标放在一个地方是,就会触发事件,最后读出结果,并写到页面上,数据传输的格式是用XML来搞定的。问题来了,在Firefox成功显示,但是IE中总提示没有对象!大侠们救命啊!
代码如下:加粗的地方都是缺少对象的!
var xmlHttp;
var cityName;
function china(city)
{
xmlHttp = null;
cityName = city;
var url = "dynamicXML.aspx?cityName="+cityName+"&type=china";
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
if(xmlHttp!=null)
{
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = statechanged1;
xmlHttp.send(null);
}
else
{
alert("你的浏览器不支持AJAX功能!");
}
}
function statechanged1()
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
var xml = xmlHttp.responseXML;
var winds = xml.getElementsByTagName("winds")[0].getElementsByTagName("wind");
var tempers = xml.getElementsByTagName("tempers")[0];
var img1s = xml.getElementsByTagName("img1s")[0];
var img2s = xml.getElementsByTagName("img2s")[0];
var weathers = xml.getElementsByTagName("weathers")[0];
var times = xml.getElementsByTagName("times")[0];
var Weather1="",Weather2="",Weather3="",Weather4="",Weather5="",Weather6="",Weather7="",Weather8="",
date1="",date2="",date3="",date4="",date5="",date6="",date7="",date8="",
WindState1="",TemperatureState1="",picture11="",picture12="",
WindState2="",TemperatureState2="",picture21="",picture22="",
WindState3="",TemperatureState3="",picture31="",picture32="",
WindState4="",TemperatureState4="",picture41="",picture42="",
WindState5="",TemperatureState5="",picture51="",picture52="",
WindState6="",TemperatureState6="",picture61="",picture62="",
WindState7="",TemperatureState7="",picture71="",picture72="",
WindState8="",TemperatureState8="",picture81="",picture82="";
WindState1 = winds[0].firstChild.nodeValue;
WindState2 = winds[1].firstChild.nodeValue;
WindState3 = winds[2].firstChild.nodeValue;
WindState4 = winds[3].firstChild.nodeValue;
WindState5 = winds[4].firstChild.nodeValue;
WindState6 = winds[5].firstChild.nodeValue;
WindState7 = winds[6].firstChild.nodeValue;
WindState8 = winds[7].firstChild.nodeValue;------解决方案--------------------
responseXML,我曾经也遇到此类问题,结果XML文件不符合XML文件标准,其它浏览器可以识别,IE非要标准的XML文件,即有一个XML头文件,一个根元素.