3 : LOADING
the response is in the process of being received
4 : DONE
the full response has been received
As the request progresses, this value is updated and the onreadystatechange event
fires. The first task is to attach a callback function to the onreadystatechange event.
This is the function that will be called every time the status of the response changes:
xhr.onreadystatechange = processResponse;
processResponse is the name of a callback function (without any parentheses as we
don't want to call it at this point!). It can be called anything you like and can even be an
Opening the Request
Next we need to call the open() method. This method sets up the request and takes three
• The first parameter is the HTTP verb, which will be used to send the response.
There are a number of HTTP verbs, but the most common are GET for retrieving
data and POST for sending data.
Note: HTTP Verbs
The Web is built upon the Hypertext Transfer Protocol, or HTTP.
When a client (usually a browser) makes a request to a server, it
contains information about which HTTP verb to use. HTTP verbs
are the language of HTTP and tell the server what type of request is
being made, which determines how it will deal with the request.
The five most commonly used verbs when dealing with resources
on the Web are:
Search WWH ::