简体   繁体   中英

Javascript XML reading problem

I'm having problems reading an XML local input. The weird thing is that this code works perfectly when the XML is located on a server(This is desktop, by the way, so no SOP problems). I can't figure this out for the life of me, and I've been staring at it, trying different things for a couple of hours.

And another question: does the XML document need a css sheet to be properly read? I would imagine that it doesn't, but I don't know too much about it.

function verify()
{                   
    zipObj = new ActiveXObject("Msxml2.XMLHTTP");
    zipObj.open("GET", "KMSY.xml", false);
    zipObj.onreadystatechange = function() {

            if (zipObj.readyState === 4) {

                 zipXML = zipObj.responseXML;
                 read(zipXML);
            } 
            else {
             document.getElementById("notice").innerHTML = zipObj.readyState;
            }
    }   
    zipObj.send();
}

function read(zipXML)
{
    var temp = zipXML.getElementsByTagName("temp_f")[0].childNodes[0].nodeValue;

    document.getElementById("notice").innerHTML = temp;
}

Import the XML file to a local server, AJAX obviously needs the XML files to be on web server in order to parse them, or so my humble experience tells me.

You might also want to add the compatibility code for other XML requests into your code.

new XMLHttpRequest() for all browser and IE 8+

new ActiveXObject("Microsoft.XMLHTTP") IE prior to 8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM