开发者

"Object Required" error in IE8 when using getElementsbyTagName

I have the following code:

 if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
}
else // for older IE 5/6
{
    xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}

var url = 'payment/code/xml开发者_StackOverflow中文版relay.php?t=rates&id=' + str;
xmlHttp.open('GET', url, false);
xmlHttp.send();
xmlDoc = xmlHttp.responseXML;
xmlResult = xmlDoc.getElementsByTagName('Result')[0].firstChild.nodeValue;

Accessing the following empty XML file from a webserver :

<?xml version="1.0" encoding="UTF-8"?><Property><Result>0</Result></Property>

or the following full one:

<?xml version="1.0" encoding="UTF-8"?>
<Property>
  <Result>1</Result>
  <Rateable>1</Rateable>
  <Location>123 Main Road, Everytown</Location>
  <Instalment>$100.00</Instalment>
</Property>

This works in Firefox, Chrome, Safari and Opera but in Internet Explorer 8 it returns the error "Object Required" for this line:

xmlResult = xmlDoc.getElementsByTagName('Result')[0].firstChild.nodeValue;

I've had a search around but have been able to find anything that works. Any suggestions would be appreciated.

Cheers Tama


The problem was the content type of the XML file. It had a content type of

application/rss+xml

I changed that to

text/xml

and it all works fine now.

Thank you for your comments, sorry it was right under my nose all along.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜