Upload local XML file using javascript in Google Chrome

I think that before the v5 version of Google Chrome, the code below worked. Now in the latest version, I get the following error when opening my web page locally:

"XMLHttpRequest cannot load the file: /// C: /Temp/Course.xml. Cross-start requests are only supported for HTTP."

Javascript Code:

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;
}

I really do not want you to open a web page from a web server each time.

+3
source share
2 answers

Local file access is disabled by default for security reasons. Try launching Google Chrome from the command line with the argument --allow-file-access

+6
source

, - html xml localhost.

, , xml.

- - http://www.server2go-web.de/

0

All Articles