0

我有以下代码:

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

var url = 'payment/code/xmlrelay.php?t=rates&id=' + str;
xmlHttp.open('GET', url, false);
xmlHttp.send();
xmlDoc = xmlHttp.responseXML;
xmlResult = xmlDoc.getElementsByTagName('Result')[0].firstChild.nodeValue;

从网络服务器访问以下空 XML 文件:

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

或以下完整的:

<?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>

这适用于 Firefox、Chrome、Safari 和 Opera,但在 Internet Explorer 8 中,它会为此行返回错误“需要对象”:

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

我已经四处搜索,但能够找到任何有效的东西。任何建议,将不胜感激。

干杯多摩

4

1 回答 1

1

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.

于 2010-09-14T04:31:02.033 回答