Loading a file on the server - timing issues?
- From: joe <mt@xxxxxxxxxxx>
- Date: Fri, 25 Apr 2008 16:04:05 +0300
I am loading a text file to a variable with XMLHttpRequest()
There seems to be some sort of timing issue since loadXML (source code below)
returns the contents of the file on seconds try. In Firefox I get an empty
string. No errors are reported.
If I look at the code with Firefox debugger (Venkman) everything works fine. I
should probably put a loop somewhere to check when loading the file is finished.
var xmlhttp;
...
[a lot of Javascipt code here]
...
loadXMLDoc("http://wwww.mysite.com/test.bin");
mystr=xmlhttp.statusText;
...
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Browser not supported.");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status!=200)
{
alert("Problem:" + xmlhttp.statusText);
}
}
}
.
- Follow-Ups:
- Re: Loading a file on the server - timing issues?
- From: Martin Honnen
- Re: Loading a file on the server - timing issues?
- Prev by Date: Re: Links in designMode
- Next by Date: Re: Loading a file on the server - timing issues?
- Previous by thread: if else syntax -
- Next by thread: Re: Loading a file on the server - timing issues?
- Index(es):
Relevant Pages
|
Loading