readyState Property
The readyState property defines the current state of the
XMLHttpRequest object.
Here are the possible values for the readyState propery:
State |
Description |
0 |
The request is not initialized |
1 |
The request has been set up |
2 |
The request has been sent |
3 |
The request is in process |
4 |
The request is completed |
You can also check the status of the response to see if
it is Good.
The next thing to check is the status code of the HTTP server
response. All the possible codes are listed on the W3C
site. For our purposes we are only interested in 200
OK response.
if (http_request.status == 200) {
// perfect!
} else {
// there was a problem with the request,
// for example the response may be a 404 (Not Found)
// or 500 (Internal Server Error) response codes
} |