Xml 为什么我的XHTML文件在IE中被拒绝访问
给出以下代码:Xml 为什么我的XHTML文件在IE中被拒绝访问,xml,internet-explorer,xhtml,access-denied,Xml,Internet Explorer,Xhtml,Access Denied,给出以下代码: <?xml version="1.0" encoding="ISO-8859-1" ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Informations</title> <script language="JavaScript"> function
<?xml version="1.0" encoding="ISO-8859-1" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Informations</title>
<script language="JavaScript">
function chargeDocument(URI) {
try {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", URI,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
afficheTitres(xmlhttp.responseXML);
}
}
xmlhttp.send(null);
} catch(o) {alert(o);}
}
function afficheTitres(doc) {
titres = doc.getElementsByTagName("title");
elementol = document.createElement("ol");
var longueur = titres.length;
for ( k = 0; k < longueur ; ++k) {
elementli = document.createElement("li");
elementli.appendChild(
document.createTextNode(
titres[k].firstChild.nodeValue
)
);
elementol.appendChild(elementli);
}
body = document.getElementsByTagName("body").item(0);
body.appendChild(elementol);
}
</script>
</head>
<body>
<ul>
<li><a href="javascript:chargeDocument('infos.xml');">By clicking there, you'll have the info</a></li>
</ul>
</body>
</html>
信息
函数文档(URI){
试一试{
xmlhttp=新的XMLHttpRequest();
open(“GET”,URI,true);
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4){
附件(xmlhttp.responseXML);
}
}
xmlhttp.send(空);
}捕获(o){alert(o);}
}
功能附件(doc){
titres=doc.getElementsByTagName(“title”);
elementol=document.createElement(“ol”);
var longueur=滴定度长度;
对于(k=0;k longueur;++k){
elementli=document.createElement(“li”);
依附儿童(
document.createTextNode(
标题[k].firstChild.nodeValue
)
);
elementol.appendChild(elementli);
}
body=document.getElementsByTagName(“body”).item(0);
附体儿童(elementol);
}
当我用IE打开xhtml文件时,它会给我一个“点击那里,你就会得到信息”,但当我点击链接时,会弹出“拒绝访问”。为什么?我同意阿洛奇的观点。在任何浏览器中,像
D:\infos.xml
这样的本地文件协议都无法访问它。如果我使用http://...
,它可以通过单击文本来显示信息
因此,您需要将其托管在web服务器中才能访问资源。您可以检查结果:
本地XHTML文件,或来自web服务器?本地XHTML文件这是跨源资源共享(CORS)的一个不方便的功能。浏览器将其他本地资源(如infos.xml文件)视为来自不同的来源,并且由于没有授予(或授予,据我所知)从不同来源访问资源的权限,因此访问被拒绝。最好的解决方案是使用一个简单的web服务器来提供文件。谢谢!成功了。我为chrome安装了一个web服务器,并用它打开了文件。