我嘗試了一些XML和XSLT的東西裝入這個下面的HTML文件:無法讀取谷歌瀏覽器的XML和/或XSLT
<html>
<head>
<script>
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;
}
function displayResult()
{
xml=loadXMLDoc("FooBar.xml");
xsl=loadXMLDoc("FooBar.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("FooBar").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("FooBar").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="FooBar" />
</body>
</html>
的問題是,這個代碼完全在蘋果Safari瀏覽器沒有警告或錯誤。 但在Chrome上,它說XMLHttpRequest cannot load file:///C:/Path/To/fooBar.xml. Cross origin requests are only supported for HTTP.
另一個問題是我不會在任何服務器上部署de xml,xslt和html。
任何人都可以幫忙嗎?
謝謝。