Making Requests

One of the most important functionalities of our Ajax object is making XHRs. In order to make this process more streamlined and easier to manage, we will be creating a method named makeRequest. This method will take three parameters: The first is a method in which to make the request, which will consist of either a POST or a GET method. The second parameter is the URL in which to make the request; this URL also will include our query string for passing data to the server when we make a request. The last parameter is the callback method, which we will want to invoke to handle the response when the ready state is completed. Listing 6.2 shows the entire method for handling this functionality.

Listing 6.2. Streamlining the Process ...

Get Ajax for Web Application Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.