Cor*_*nel 3 javascript xml google-chrome
我认为直到谷歌浏览器的第5版,以下代码才有效.现在在最新版本中,我在本地打开网页时出现以下错误:
"XMLHttpRequest无法加载file:/// C:/Temp/Course.xml.只有HTTP支持交叉原始请求."
Javascript代码:
function getXmlDocument(sFile) {
var xmlHttp, oXML;
// try to use the native XML parser
try {
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", sFile, false); // Use syncronous communication
xmlHttp.send(null);
oXML = xmlHttp.responseXML;
} catch(e) {
// can't use the native parser, use the ActiveX instead
xmlHttp = getXMLObject();
xmlHttp.async = false; // Use syncronous communication
xmlHttp.resolveExternals = false;
xmlHttp.load(sFile);
oXML = xmlHttp;
}
// return the XML document object
return oXML;
}
// get the best ActiveX object that can read XML
function getXMLObject() {
// create an array with the XML ActiveX versions
var aVersions = new Array("Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0");
// loop through the array until we can create an activeX control
for (var i=0; i<aVersions.length; i++) {
// return when we can create the activeX control
try {
var oXML = new ActiveXObject(aVersions[i]);
return oXML;
}
catch(e) {
}
}
// could not create an activeX, return a null
return null;
}
Run Code Online (Sandbox Code Playgroud)
我真的不想每次都被迫从Web服务器打开网页.
| 归档时间: |
|
| 查看次数: |
13272 次 |
| 最近记录: |