Hello,
Im using javascript to load a simple xml document, using the following code:
//Name: loadXML
//Purpose: To load xml at any location
var xmlDoc;
function loadXML(strPath) {
//code for IE
if(window.ActiveXObject) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
//xmlDoc.onreadystatechange = getXMLState;
xmlDoc.load(strPath);
return xmlDoc;
} else if(document.implementation && document.implementation.createDocument) { // mozilla
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load(strPath);
return xmlDoc; // returning data before entire document is loaded
}
}
And i am calling the code like so:
//load the xml data
var objXmlTmp = loadXML('/data/formData2.xml');
//alert('Number of objXmlTmp nodes = ' + objXmlTmp.childNodes.length);
//get the nodes
var objXml = objXmlTmp.getElementsByTagName('list');
//alert('Length of objXml nodes in top function = ' + objXml.length);
My problem is that if you uncomment the last alert statement, it will return "Length of objXml nodes in top function = 0", however if you additionally uncomment the first alert statement, the last alert statement will return "Length of objXml nodes in top function = 3". I am therefore convinced that this is because Firefox is calling the XML asynchronously, and by executing the alert statements the code is having enough time to finish loading the xml.
Can anyone help modify my code so that the firefox version also loads asychronously?
Thanks in advance
Al
http://www.webmasterworld.com/forum91/3517.htm
Open in new window