Trademarks: Page 4 of 6

Creating and sending XMLHttpRequest

For exchanging information between a webpage and a server, you use a XMLHttpRequest object. And as mentioned before, this will allow us to update different parts of a web page without having to reload the entire web page.

i.e:

xmlHTTPRequest = new XMLHttpRequest();

 

Once you have your XMLHttpRequest object you can now exchange information with the server, to do this you will use two methods from the object:

  • open(TypeOfRequest,ServerURL,CommunicationType)
    • TypeOfRequest: set it to GET or POST
    • serverURL: the location of the file retrieved
    • CommunicationType: TRUE for Asynchronous or FALSE for Synchronous

i.e:

xmlHTTPRequest.open("GET","AjaxJSONResponse.json",true);

 

  • send(data)
    • data: a String object with additional data needed for POST requests.

i.e:

xmlHTTPRequest.send();

 

 

Like us on Facebook