Forum Moderators: open
loadXMLfromDatabase();
doSomethingWithNewElements();
The problem is my script tries to doSomethingWithNewElements() before it's finished loadXMLfromDatabase().
I get the classic Object Expected error.
I found that this works:
loadXMLfromDatabase();
alert("it's loaded now");
doSomethingWithNewElements();
which is promising, but I don't want an alert in there.
How do I wait until the XML is loaded before going on to the next command?
You'll need a function like theirs, which they call from a
req.onreadystatechange(where
reqis the reference to the XML object).
function processReqChange() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}