• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking Ajax ready state  RSS feed

 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's your code, and what specific problems are you having with it?
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please provide some pointers for that.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search this page for the word "timeout" and it should give you the clues you need to progress.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!