Load xml from javascript

后端 未结 3 1093
不思量自难忘°
不思量自难忘° 2021-01-03 14:55

Totally new to XML and I\'ve been struggling on this very simple objective for too long (though I can find enough on the internet about it). Just need the values out of this

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 15:43

    // load xml file
    if (window.XMLHttpRequest) {
       xhttp = new XMLHttpRequest();
    } else {    // IE 5/6
       xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xhttp.open("GET", "pricing.xml", false);
    xhttp.send(null);
    xhttp.onreadystatechange = function(){
     if (xhttp.status == "200")
    xmlDoc = xhttp.responseXML; 
    }
    var uurloon = xmlDoc.getElementsByTagName("uurloon")[0].childNodes[0].textContent;
    var setloon = xmlDoc.getElementsByTagName("setloon")[0].childNodes[0].textContent;
    alert('end');
    

提交回复
热议问题