XMLHttpRequest benefits

One of the important challenges facing Ajax developers is how to respond when an XMLHttpRequest is not available. While most modern browsers support XMLHttpRequest, there are always users whose XMLHttpRequest is not supported or whose browser security has prevented XMLHttpRequest from executing. If you are developing a Web application that is applicable on a corporate network, you probably have an advantage in determining which browsers are supported and when XMLHttpRequest is always available. If you’re developing for a public network, you should know that by assuming that XMLHttpRequest is available, you’re disowning users of older browsers, closed-access people browsers, or lightweight browsers with a service against running your application.

So you need to try to make your application with “graceful degradation” to remain functional even in browsers without XMLHttpRequest support. In the shopping cart example, the best way to degrade your app is with Add to Cart buttons, which perform the usual role of refreshing the page for a new cart status. With Ajax, you can add to the page via JavaScript code when the page is loaded, attaching a JavaScript statement to each Add to Cart button, as long as XMLHttpRequest is available. Another way is to define the XMLHttpRequest when the user is logged in, and then provide any Ajax version of the application or a version based on normal forms, if needed.

Regarding usability
Some of the goals of usability in Ajax are quite general. For example, it may be important to let users know that their input is registered, since the usual feedback mechanism (“hourglass” cursor and “spinning browser”) is not applicable to XMLHttpRequest. The way out is to replace the Confirm buttons with the message “Refreshed…” so that users don’t have to click the buttons multiple times while waiting for a request.

Another challenge is that users may not notice that the parts of the page they are seeing have already been updated. You can solve this problem by using many visual techniques and tricks, such as drawing the user’s eye to the updated parts of the page. Other problems caused by page updates with Ajax include a non-functional back button, incorrect address display, or the inability to add to favorites. See the Resources section for articles that specialize in tasks of functionality in Ajax applications.

Server overload
Running an Ajax interface in a place where normal forms work can lead to an unexpected increase in the number of requests to the server. For example, a normal Google Web search triggers a single request to the server when a user clicks the search button. However, Google Suggest, which tries to automatically complete your search action, sends multiple requests to the server while the user is typing. When you develop an Ajax application, be aware of how many requests you send to the server and whether this causes server congestion. You can reduce server overload by storing queries on the client side and hiding them in the client if possible. You can also try to design Ajax applications so that most of the action can be done in the client side of your code without having to connect to the server.

Dealing with asynchrony
It is very important to understand that there is no guarantee that XMLHttpRequests will end up in the exact order in which they were sent. In fact, you need to assume that they won’t return that way, and design your application with that correction in mind. In the shopping cart example, the marking time of the last updated product earlier ensured that newer cart data could not be overwritten by older cart data. This flawed approach works for the shopping cart scenario, but may not work in other scenarios.

To conclude.
You must by now have a good understanding of the basic principles of Ajax programming and the characteristics of the server and client components that take place in Ajax. This is the foundation of an Ajax application in Java. In addition, you should understand some of the higher abstract level development tasks that appear with the Ajax techniques. Creating a successful Ajax application will require a general approach, from developing interfaces using JavaScript code to server architecture, but you are now armed with the basic Ajax programming principles necessary to address all of these aspects.