HTML and CSS Reference
In-Depth Information
Table 18.4
Some HTTP Status Codes (continued)
HTTP Status Code
401 Unauthorized
The request requires user authentication.
404 Not found
The server found nothing matching the URI given.
500 Internal Server Error
The server encountered an unexpected error and couldn't fulfill
the request.
503 Service Unavailable
The server is currently unable to handle the request due to
temporary overloading or maintenance.
For a descriptive table of all the HTTP status codes, go to
and for complete technical definitions of these codes, go to
EXAMPLE
(S
AMPLE
C
ODE
)
ajaxRequest.onreadystatechange = function()
{
if (
objectRequest.status == 200) {
// OK
}
else if(
ajaxRequest.status == 404
){
// Resource not found
}
else{
alert("Error:" +
ajaxRequest.statusText
);
}
}
The function that will check for the status of a request and handle the information
returned from the server is called a callback function or an inline function. The object's
onreadystatechange
event handler is assigned a reference to the callback function.
The data sent back from a server can be retrieved with two other properties of the
XMLHttpRequest
object called the
responseText
property and the
responseXML
property.
The
responseText
Property.
For simple Ajax applications, such as getting text from
a file, you can retrieve the server's response in a string with the
responseText
property.