In order to understand exactly how Ajax concepts are put together, it is important to
know how a web site processes a request and receives a response from a web server. The
current standard that browsers use to acquire information from a web server is the HTTP (HyperText Transfer Protocol) method (currently at version HTTP/1.1). This is the means a web browser uses to send out a request from a web site and then receive a response from the web server that is currently in charge of returning the response.
HTTP requests work somewhat like e-mail. That is to say that when a request is sent,
certain headers are passed along that allow the web server to know exactly what it is to be serving and how to handle the request. While most headers are optional, there is one header that is absolutely required (provided you want more than just the default page on the server): the host header. This header is crucial in that it lets the server know what to serve up.
Once a request has been received, the server then decides what response to return.
There are many different response codes. Table below has a listing of some of the most
common ones.
Table: Common HTTP Response Codes
Code | Description |
---|---|
200 OK | This response code is returned if the document or file in question is found and served correctly. |
304 Not Modified | This response code is returned if a browser has indicated that it has a local, cached copy, and the server’s copy has not changed from this cached copy. |
401 Unauthorized | This response code is generated if the request in question requires authorization to access the requested document. |
403 Forbidden | This response code is returned if the requested document does not have proper permissions to be accessed by the requestor. |
404 Not Found | This response code is sent back if the file that is attempting to be accessed could not be found (e.g., if it doesn’t exist). |
500 Internal Server Error | This code will be returned if the server that is being contacted has a problem. |
503 Service Unavailable | This response code is generated if the server is too overwhelmed to handle the request. |
It should be noted that there are various forms of request methods available. A few of them, like GET and POST, will probably sound quite familiar. Table below lists the available request methods (although generally only the GET and POST methods are used).
Table: HTTP Request Methods
Method | Description |
---|---|
GET | The most common means of sending a request; simply requests a specific resource from the server |
HEAD | Similar to a GET request, except that the response will come back without the response body; useful for retrieving headers |
POST | Allows a request to send along user-submitted data (ideal for web-based forms) |
PUT | Transfers a version of the file request in question |
DELETE | Sends a request to remove the specified document |
TRACE | Sends back a copy of the request in order to monitor its progress |
OPTIONS | Returns a full list of available methods; useful for checking on what methods a server supports |
CONNECT | A proxy-based request used for SSL tunneling |
Now that you have a basic understanding of how a request is sent from a browser to a server and then has a response sent back, it will be simpler to understand how the XMLHttpRequest object works. It is actually quite similar, but operates in the background without the prerequisite page refresh.
No comments:
Post a Comment