hi,
My problem is how to determining when the XML file has loaded using
javascript.
I loaded an xml file using javascript in a web page.
The code below is loading the xml file for IE:
this.xmlDoc= new ActiveXObject("Microsoft.DomDocument");
this.xmlDoc.load(url);
The code below is loading the xml file for NS7 and FireFox0.9.3:
this.xmlDoc = document.implementation.createDocument("","doc",nu ll);
this.xmlDoc.load(url);
I want to make sure the xml file is loaded successfully, or to time
out at 0.5 seconds.
problems in IE:
I use a while loop to check this.xmlDoc.readyState after the load,
I didn't set the xmlDoc.asnyc to false since i want to time out if
loading is very time-consuming.
var today = new Date();
var now = today.getTime();
while(1)
{
//alert(this.xmlDoc.readyState);
var today2 = new Date();
var now2 = today2.getTime();
if((now2 - now) > 500 || (this.xmlDoc.readyState == 4))
{
alert(now2 - now);
return;
}
}
However, I get timed-out every time! Even I change 500 to 5000, IE
will hang for 5 seconds and time-out.There is only a small xml file to
load. It shouldn't take that long!
Is it because dom loads the xml asynchronously and the while loop
takes higher priority than the loading thread?Or is there any way i
can manipulate the multi-thread behavior?
If i use synchronous loading, how can I wait for a while in the func
before return and time-out the loading when necessary?
problems in NS, FireFox:
there is no property such as this.xmlDoc.readyState to check.
Is this.xmlDoc.onload a good way to detect the completion of loading?
What if i have to time out the loading after 0.5 seconds?
Any suggestion?
Thanks,
Roy