I am really struggling with a Jquery script I can't get to work.
I have an XML string and I want to return the name 'Miki' from it, however its just not working and i can't figure it out. Can someone help me?
function LoadParseXML() {
var xml
xml = '<?xml version="1.0" encoding="utf-8"?><CATALOG><VAR><PREVIOUSPAT>Miki</PREVIOUSPAT></VAR></CATALOG>';
loadXMLDoc(xml, 'PREVIOUSPAT');
}
function loadXMLDoc(url, Node) {
var xmlhttp;
var txt, x, xx, i;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
x = xmlhttp.responseXML.documentElement.getElementsByTagName("VAR");
for (i = 0; i < x.length; i++) {
xx = x[i].getElementsByTagName(Node);
txt = xx[0].firstChild.nodeValue;
alert(txt);
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
xxvariable and see what's inside$.ajax()and$.parseXML()which should hopefully fix any problems you're having. For traversal through the XML document, use jQuery methods like.find(),.filter(), or.children(). And then.text()to retrieve element content