guitardave78
Programmer
Hi this function checks an xml file to see if the test value matches anything in the xml file.
Here is the funciton
Test1 should return true, but it seems that it returns the value of the function before it executes the bit in the middle (onreadystatechange = function()) so if i set it to retrun a value at the end of the function and then put an alert in the onreadystatechange = function() bit, i get the value of the function then i get the alert box (seems the wrong way round to me).
}...the bane of my life!
Here is the funciton
Code:
var xmlhttp
var clans
var matched = false
function testagainstXML(url,node,test) {
//document.getElementById("maps").innerHTML = "Loading...";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
xmlhttp.overrideMimeType("text/xml");
}else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var xmlDoc = xmlhttp.responseXML;
for(n=0;n<xmlDoc.getElementsByTagName(node).length;n++){
var xmlNodes = xmlDoc.getElementsByTagName(node)[n].firstChild.data;
if(xmlNodes == test){
var matched = true
}
}
}else{
alert("There was a problem retrieving the XML data:\n" + xmlhttp.statusText);
}
}
}
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader('content-type', 'text/xml');
xmlhttp.send(null);
}
alert(testagainstXML("registerxmlgen.asp","clanname","Test1"))
Test1 should return true, but it seems that it returns the value of the function before it executes the bit in the middle (onreadystatechange = function()) so if i set it to retrun a value at the end of the function and then put an alert in the onreadystatechange = function() bit, i get the value of the function then i get the alert box (seems the wrong way round to me).
}...the bane of my life!