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("htt p://wwww.mysite.com/test.bin");
mystr=xmlhttp.s tatusText;
...
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttp Request)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest( );
}
else if (window.ActiveX Object)
{// code for IE6, IE5
xmlhttp=new ActiveXObject(" Microsoft.XMLHT TP");
}
if (xmlhttp!=null)
{
xmlhttp.onready statechange=sta te_Change;
xmlhttp.open("G ET",url,true) ;
xmlhttp.send(nu ll);
}
else
{
alert("Browser not supported.");
}
}
function state_Change()
{
if (xmlhttp.readyS tate==4)
{// 4 = "loaded"
if (xmlhttp.status !=200)
{
alert("Problem: " + xmlhttp.statusT ext);
}
}
}
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("htt p://wwww.mysite.com/test.bin");
mystr=xmlhttp.s tatusText;
...
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttp Request)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest( );
}
else if (window.ActiveX Object)
{// code for IE6, IE5
xmlhttp=new ActiveXObject(" Microsoft.XMLHT TP");
}
if (xmlhttp!=null)
{
xmlhttp.onready statechange=sta te_Change;
xmlhttp.open("G ET",url,true) ;
xmlhttp.send(nu ll);
}
else
{
alert("Browser not supported.");
}
}
function state_Change()
{
if (xmlhttp.readyS tate==4)
{// 4 = "loaded"
if (xmlhttp.status !=200)
{
alert("Problem: " + xmlhttp.statusT ext);
}
}
}
Comment