My mobile app needs to send Ajax request and know the difference between if the server is down or the server is live but is giving error.

I understand that if there is some server error, the server will return response with 50X code.

But what will happen if the server is down. What error will the client get?

I searched but its confusing me - People are advising that your server should be set to respond with code 503 if its on maintenance. But I cant understand the fact - that the server is down, how can it even send 503 response back??

  • 6
    If your server is down like in: shutdown, or service not started, you obviously can't send a custom error code. You will get an unreachable error (or something, it depends) and your app can react to that.
    – Lenniey
    Commented Jul 11, 2017 at 11:29

1 Answer 1


It is usually the front end load balancer that sends the 503 Service Unavailable error if the actual web server is down. If you don't have a load balancer and the server behind it is down, or if the load balancer is down, the client will get a Connection timeout. If the server is up but Apache is not started the client will get Connection refused.

In the server down case the AJAX call itself will return an error.

response = url.open("http://...");
if (response == NULL) { /* handle Connection timeout / Conn refused */ }

In the 503 case your AJAX call actually performs a HTTP request, except that the error code says that there was a problem. Something like:

response = url.open("http://...");
if (response.code == 503) { /* handle service unavailable */ }

Hope that helps :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .