| Author |
Checking Ajax ready state
|
Anubh Jain
Ranch Hand
Joined: Apr 09, 2012
Posts: 34
|
|
Hi all,
I need some help in javascripting.
I am using a xmlhttprequest object wherein i expect a readystate of 4 from the server.
I need to put a check wherein if I dont receive a readsystate of 4 in certain time(say 1 sec), i want to display a error message.
Please show some pointers to this.
Thanks in advance.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
|
Where's your code, and what specific problems are you having with it?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Anubh Jain
Ranch Hand
Joined: Apr 09, 2012
Posts: 34
|
|
Thanks bear for pointing out about title.
I have a code of something like:
No in case my server is down, or connection in disconnected, I am recieving any response. So how do I put a timeout so that I can return an error message.
I hope it makes picture a little clear.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
|
Any reason that you are doing this "by hand" as opposed to with a library like jQuery that already has that built in?
|
 |
Anubh Jain
Ranch Hand
Joined: Apr 09, 2012
Posts: 34
|
|
Please provide some pointers for that.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
http://api.jquery.com/category/ajax/
If you want to go it alone, you'll need to set a timeout and cancel the request if it expires. Don't forget to cancel the timer if it doesn't time out.
|
 |
Anubh Jain
Ranch Hand
Joined: Apr 09, 2012
Posts: 34
|
|
Now in this code where do i put the timeout so that when the response is not received in particular time, error is displayed.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
|
Search this page for the word "timeout" and it should give you the clues you need to progress.
|
 |
 |
|
|
subject: Checking Ajax ready state
|
|
|