AJAX – increase your web speed


AJAX (Asynchronous JavaScript and XML.) is not a new programming language, but a new way to use existing standards.

AJAX’s intention is to make web pages become faster and therefore more accepted, by doing background exchange of some small amounts of data with the server, in order to avoid the page to be reloaded on every user action. It aims to increase interactivity, speed and ease of use for web applications.

It  uses an ensemble of technologies: HTML,XHTML,CSS,Javascript,the XMLHttpRequest object for information exchange and manipulation in an asynchronous way with the web server, and XML which is used for data transfer between the server and client, even though any format works, including HTML, simple text, etc.

AJAX was made popular in 2005 by Google (with Google Suggest – When you start typing in Google’s search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.)

The keystone of AJAX is the XMLHttpRequest object. All new browsers use the built-in JavaScript XMLHttpRequest object to create an XMLHttpRequest object (IE5 and IE6 uses an ActiveXObject). With the XMLHttpRequest object, a web page can make a request to, and get a response from a web server – without reloading the page.

Before sending data off to a server, it might help to take a look at three important properties of the XMLHttpRequest object here

My example is about using AJAX  along with Spring and Hibernate.
We have a web application that has tabs for different behavior/views in the application. Assuming that these tabs hold different logic,but they all have in common a filter zone that can either be collapsed (this is done by a HTML div that is initially hidden) or expanded (the div is visible). The challenge is to remember the state (is it collapsed,or expanded?) of this filter zone for all of the tabs without doing a submit (in order not to repeat a lot of operations when not needed,so to be faster).This way, when changing to another tab, if the filter zone was expanded on a previous one, we will also see it extended here, in the current tab.

So,we have the div

<div id="filterZone" style="display: ${state}">...</div>

and a link

<a href="#" onclick="showFilterZone();">More...</a>

The “More” link sends us to a javascript function:

function showFilterZone() {
    filterZone.style.display = 'block';

This function shows the filter zone,and also calls “ajaxCall” function

function ajaxCall(url,state){
if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
if (req != undefined) {
    req.open("GET", url, true);

Following is the ajaxCall function explained:

    -first we create a variable named req to hold the XMLHttpRequest object. Depending on the browser it can be XMLHttpRequest, or ActiveXObject for IE6 and IE5.
    -the function receives an URL “setUIState.htm?extDateFilter=visible” which is sent to the server.
    To send off a request to the server, we use the open() and send() methods.

  • The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously.
  • The send() method sends the request off to the server

This function does what would normally happen if you would copy and paste the URL into the browser,only it does this in the background. Normally you could also specify a function which is called after you get a response back from the server,but in this example it’s not the case.

From here on,this URL can be mapped, in Spring for example, to a controller, which basically uses an object to store this information for the whole session. So we have the filter zone state remembered for the whole session. Now we have to tell every new page to be loaded to get this state. For this we use an interceptor, which is called before and after every call to a controller. Before a page loads we can get this state and send it to the page. This way we’ll have on every page the state for the filter div that we changed and remembered it with the help of AJAX and Spring.

Similarly, this whole process can be repeated for hiding the <div>. A javascript function will be called, which remembers the hidden attribute,then calls ajax, which calls an URL. Spring comes here,and remembers this new state. From now on on every page call, the interceptors will send to every page the new state.

Read more about Spring interceptors here

For more examples of what can be achieved by using AJAX, visit http://www.ajaxdaddy.com/

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.