Here a sample how to load a page with Javascript.
Be adivsed that it returns immediately. So if you use it to intialize variables
do them in "whatever" function.
Here' what I mean (pseudocode):
line 0: ..
line 1: blah, blah;
line 2: loadXMLDoc(..); //loads a value to "myvar"
line 3: if (myvar==1)
line 4: blah, blah;
line 5: ...
When execution of code reaches Line 4 you'd expect "myvar" to have some value.
Not so! Caveat! "whatever" is executed (see below example code) when it's good
and ready. loadXMLDoc(..) returns immediately (well almost).
loadXMLDoc("
http://www.yourhomepage.com/somefile.txt");
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=whatever;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support it.");
}
}
function whatever()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
myvar=1; //remove this line, not necessary
alert("It worked, here's the contents:" + xmlhttp.responseText);
}
else if (xmlhttp.status==404)
{
alert("Dang! no workee:" + xmlhttp.responseText);
}
else
{
alert("Som uther problemo:" + xmlhttp.responseText);
}
}
}