Ajax

G

Gandalf

Hi everyone,
I building an Ajax application that need a while before it return
back the data.
How can I check with javascript if the application status is 'loading'
to show the user a message or something?

p.s: I tried to use if(http.realState==2 || http.realState == 3 ) in
the function that send the request
like this:

get_lines.open("POST", 'calc.php', true);

get_lines.setRequestHeader('Content-Type','application/x-www-form-
urlencoded');
if(get_lines.readyState == 3){
document.getElementById('loading').style.display='';

}
get_lines.onreadystatechange = handleCalc;



and it didn't worked

thanks
 
T

Thomas 'PointedEars' Lahn

Gandalf said:
I building an Ajax application that need a while before it return
back the data.
How can I check with javascript if the application status is 'loading'
to show the user a message or something?

p.s: I tried to use if(http.realState==2 || http.realState == 3 ) in
the function that send the request
like this:

get_lines.open("POST", 'calc.php', true);
^^^^ == asynchronous
get_lines.setRequestHeader('Content-Type','application/x-www-form-
urlencoded');

Error-prone if untested/unhandled, and probably unnecessary.
if(get_lines.readyState == 3){

AJAX: *Asynchronous* JavaScript And XML. See below.
document.getElementById('loading').style.display='';

}
get_lines.onreadystatechange = handleCalc;

You are assigning to `onreadystatechange' to have an event listener for
the `readystatechange' event. So you have to handle that event *in* the
listener handleCalc(), _not_ outside of it.

Also, the get_lines.send(...) call is missing. You have to request
something before you can retrieve the status of the response ...

RTFM: http://developer.mozilla.org/en/docs/AJAX


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top