我需要使用JavaScript从指定的URL加载xml文件。这是我在做什么:在FF&Google Chrome中使用javascript从指定的URL加载xml中的问题
function GetXMLDoc() {
var url = 'http://www.warm.fm/exports/NowOnAir.xml';
var httpRequest = null;
try {
httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e) {
try {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e2) {
try {
httpRequest = new XMLHttpRequest();
}
catch (e3) { httpRequest = false; }
}
}
if (httpRequest) {
httpRequest.open('POST', url, false);
httpRequest.setRequestHeader("Content-Type", "text/xml");
httpRequest.send(null);
alert(httpRequest.responseText);
}
else {
alert(httpRequest);
}
它在IE中完美的工作,但它不在FF和谷歌浏览器。萤火虫显示我以下错误:
未捕获的异常:[异常... “组件返回失败代码:0x80004005的(NS_ERROR_FAILURE)[nsIXMLHttpRequest.send]” nsresult: “0x80004005的(NS_ERROR_FAILURE)” 位置:“JS帧: :http://localhost:49697/XMLParser.js :: GetXMLDoc :: line 43“data:no]
有没有人有答案可以帮助我解决问题?
感谢, Mohin酒店
你为什么不能使用像jQuery Ajax这样的JavaScript库的任何原因?它实现了跨浏览器调用 - 例如,请参阅['get()'](http://api.jquery.com/jQuery.get/)函数。 – Oded 2010-09-23 12:56:22
是的。我只想使用JavaScript和HTML,没有别的。 – Mohaimen 2010-09-23 13:01:09