Sending control back to calling function in XMLHttpRequest
Posted: Sun Aug 28, 2005 4:42 am
Code: Select all
var req;
function foo()
{
loadXMLDoc("myurl.com/myxml.xml");
// Nothing to be done until xml file is 100% loaded
DoSomething_Next();
}
function loadXMLDoc(url)
{
req = false;
if (window.XMLHttpRequest)
{
try { req = new XMLHttpRequest(); }
catch(e) { req = false; }
}
else if (window.ActiveXObject)
{
try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e)
{
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e) { req = false; }
}
}
if(req)
{
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send("");
}
}
function processReqChange()
{
if (req.readyState == 4)
{
if (req.status == 200)
// Return back to foo() - continue from line after loadXMLDoc call
else
// Error
}
}Thanks