January 20th, 2013, 12:44 PM
-
Ajax readyState
Code:
if (xmlhttp.readyState==3 && xmlhttp.status==200) {
document.getElementById("content").innerHTML="...";
}
Only readyState == 4 works!.
I also tried
Code:
while (xmlhttp.readyState == 3)
I'd like to print "..." while processing the data ..
Thx. Kr, C.
January 20th, 2013, 08:20 PM
-
The fastest way; to do this; would be something like this:
Code:
function ajaxRequest()
{
// define xmlhttp and/or other actions here
document.getElementById("content").innerHTML="...";
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
// handle responseText here
}
}
January 22nd, 2013, 02:35 PM
-
Great!
Thx, web_loone08.
There is a problem and it's strange.
If I define my XMLHttpRequest variable inside the function, the code:
Code:
document.getElementById("content").innerHTML="...";
keeps running and (xmlhttp.readyState==4 && xmlhttp.status==200) never becomes true.
Otherwise OK!
Good:
Code:
var xmlhttp;
function ajaxRequest()
{
// initialize xmlhttp and/or other actions here
document.getElementById("content").innerHTML="...";
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
// handle responseText here
}
}
Bad:
Code:
function ajaxRequest()
{
// define xmlhttp and/or other actions here
document.getElementById("content").innerHTML="...";
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
// handle responseText here
}
}
January 24th, 2013, 03:16 PM
-
You can't define your xmlhttp variable in the same function that you use to detect changes in your readyState. xmlhttp is the owner of that readyState, if you redefine xmlhttp in that function you lose the original xmlhttp.
Your "ajaxRequest" function will fire every time the readyState changes, which is why you have to check to be sure that readyState is 4 so you know the request is done. As an aside, realize that readyStates 1, 2 and 3 are poorly implemented in most browsers and are not really to be reliably used for anything. It's not uncommon for a browser to skip 2 or 3 and go straight to 4 in my experience.
January 25th, 2013, 12:36 AM
-
Yes, I am not using those states anymore cauz as u said almost nobody uses them.
When I load a simple page with xmlhttpR. and I put something before (is state 4) then it works, but in all other cases, it doesn't. Especially when I send post/get message to an PHP file to do some db stuff.. rare!!
thx, anyway...