我正在尝试使用以下代码加载外部 xml,但它不起作用
$( document ).load( "data.xml", function( response, status, xhr ) {
console.log( xhr.status + " " + xhr.statusText );
});
我两个都有data.xml
and js
文件位于同一文件夹中。
In chrome它返回404 error
.
In FF它返回0 [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"
.
我不明白为什么会发生这种情况?请阐明这个问题。
Updates:我用了一个镜头$.get()
如下所述,但仍然没有成功。
同时我也尝试使用纯js,如下所示
function loadXMLDoc(dname) {
if (window.XMLHttpRequest) {
xhttp=new XMLHttpRequest();
}
else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
xmlDoc=loadXMLDoc("data.xml");
console.log(xmlDoc);
仍然面临错误。
FF 中的错误:NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝 [中断此错误]
xhttp.send();
and
铬错误:XMLHttpRequest 无法加载 file:///C:/Users/admin/Desktop/public_html%281%29/public_html/data.xml。
仅 HTTP 支持跨源请求。 xml.js:13 未捕获
NetworkError:发生网络错误。
Updates:我找到了这个question https://stackoverflow.com/questions/6653825/error-access-to-restricted-uri-denied很有用,但是有什么办法可以解决这个问题吗?