File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Checking Ajax ready state Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Checking Ajax ready state" Watch "Checking Ajax ready state" New topic
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: 61608
    
  67

Where's your code, and what specific problems are you having with it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 61608
    
  67

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: 61608
    
  67

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: 61608
    
  67

Search this page for the word "timeout" and it should give you the clues you need to progress.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking Ajax ready state