2

I would like to know how timeouts (case where server is down) can be handled for a AJAX call. I am using Chrome v28.

I did a lot of search on google and couldn't find any convincing answer other than checking for status == 0 on the readystate callback function. Is this the only way of handling it? I am not using Jquery or any other frameworks.

Srinidhi
  • 31
  • 3

1 Answers1

0

Although I would highly recommend using jQuery for this since it really simplifies ajax calls and you can have a response set for these kinds of situations, you could use setTimeout(timeoutCallback, amountOfTime) to achieve this without worrying about statuses. Basically, the callback would abort your ajax request and handle the error however you want if the request wasnt satisfied in time. If you want more details, I got this information from this question on Stack Overflow: How to detect timeout on an AJAX (XmlHttpRequest) call in the browser?. Hope this helps!

Community
  • 1
  • 1
taylorc93
  • 3,676
  • 2
  • 20
  • 34