133
duplication prohibited
The browser will always run your callback,
because that gives you a chance to respond to
whatever the server did to handle your request.
Since you’re using an asynchronous request, the
callback is the only way you have to write code that can
deal with a server’s response. To help you out with
dealing with that response, the browser gives you both the
state of your request, and the status of your request.
There’s a different between the state of your request, and
the status of the same request. Your request’s ready state
tells the browser what stage of processing the request is in:
initialization, processing, completed, etc.. But just because
a request is complete doesn’t mean that the request was
successful... that involves the status of the request.
A server reports any problems with a request by using a status
code. The status code indicates what happened during the request,
and whether things went as you intended. So even if a request
was completed, you still need to make sure the status code for the
request indicates that everything went OK.
OK, so I see how it’s getting to the server. But if
the server can’t nd the program in the request URL
to run, why does the browser still run our callback?
Shouldn’t it report an error or something?
The browser always runs your callback...
...and it did report an error.