• working with GET and POST requests
• handling JSON formatted text and XML documents returned by the server
• handling timeouts, and aborting requests
You can read the full article here.
"Give me six hours to chop down a tree and I will spend the first four sharpening the axe." Abraham Lincoln
Part 2: Aborting a request, caching of dynamic data, handling timeouts - some of the things we need to watch out for when using the XMLHttpRequest object
In Part 1 we saw that using the XMLHttpRequest object is easy; however there are a few things we need to watch out for.
To begin with we modify Country.htm to add a ‘refresh’ button to the country dropdown from the example in Part 1. This results in the following interface:
As in the example in Part 1, the windows.onload event calls the GetAllCountries() function which populates the country dropdown with Country data after the page has loaded. Clicking the refresh button calls the GetAllCountries() function which re-populates the country dropdown.
In this post we will discuss the following questions:
What happens if the user was to click the refresh button before the request from the windows.onload event returned?
What happens if the user was to click the refresh button indiscriminately?
How do we avoid the bad effects of such actions?
How do we cancel a request once it has been sent?
How can we ensure that dynamic data is not cached by the browser?
How can we recover if a request never returns after it has been sent?
By the end of this discussion we should have a fairly robust, reusable library to handle asynchronous GET requests through the XMLHttpRequest object.
You can read the full article here.
Part 1: Asynchronous and Synchronous requests
“The XMLHttpRequest object is a data transport object that is the core of AJAX. XMLHttpRequest was introduced in 2000, mainly to enable Microsoft Outlook Web Access to display e-mails without notification. Since then, AJAX applications have gained popularity for their ability to asynchronously exchange data with a server and then display that data without having to reload the Web page on which the data appears.” [from MSDN]
The XMLHttpRequest object establishes the communication between the browser and the server over HTTP. As the video below illustrates, it is possible to setup multiple simultaneous requests bringing about a huge improvement in user experience.
In a serious Ajax based web application, you will probably be using an established javascript library, such as jQuery, which will abstract the use of the XMLHttpRequest object in efficient cross browser capable methods.
In this, and in subsequent posts, we will examine the nitty gritty of the XMLHttpRequest object.
You can read this article online here.
Code download:
You can download the example code here. This code helps you to test out the XMLHttpRequest object in an asynchronous mode. The article has details on how to set up the application.
Download the full video here [XMLHttpExample_FullVideo.rar, 384 KB] or here [XMLHttpExample_FullVideo.zip, 4.4 MB].