Click here to Skip to main content
13,554,046 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 2 Nov 2007
Licenced CPOL

Backbone of Ajax: XmlHttpRequest

, 2 Nov 2007
Rate this:
Please Sign up or sign in to vote.
An article on XmlHttpRequest and Ajax


"Ajax" is a new term which is spelled by almost all the web developers today! Does everyone know that it uses XmlHttpRequest internally? Many say "Yes", some people say "don't know". I am writing this article for all the developers who must understand XmlHttpRequest which I consider to be the backbone of Ajax.

What is Ajax?

Ajax is not really a technology, it is an architectural pattern. It is not another name for XmlHttpRequest, but a technique to call the server with the help of XmlHttpRequest, CSS, DOM, XML, HTML and other web entities.

Who is the Inventor of Ajax?

The answer is 'Nobody'. Although it is a design approach, no specific person or company owns it. "Jesse James Garrett" is the founder of this name. He used the combined web design approach in his applications, and he named it "Ajax". Google made Ajax famous, because we use Gmail and Google map interface on a day to day basis.

In this article, I'm going to concentrate on XMLHttpRequest, the backbone of Ajax. For further details on Ajax, you can refer to this link.


XmlHttpRequest is an object which is provided by almost all the browsers to enable scripted communication to the server. Using this, you can send or get any data from/to the server using JavaScript. Note that you do not need to post back your page here! Obviously, the end user is not aware about what is happening behind the scenes. This is the main reason we have the web application acting like a desktop application. Imagine Gmail, you can also use Gtalk from the browser, as we do in a desktop application.

Flow of the XmlHttpRequest

A Quick Example

I am not going to create an ASP.NET web project. Since XmlHttpRequest is common in all the web applications, everyone should understand what it is.

Here, I am going to explain how to call the HTML data from one page to another page.

Create the First HTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="" >
    <title>Calling another page</title>
    <script language="javascript" type="text/javascript">

    //Creating the instance of the XmlHttpRequest
    // branch for native XMLHttpRequest object
    var client=null;
    if (window.XMLHttpRequest)
        client = new XMLHttpRequest();
    } // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject)
        client = new ActiveXObject("Microsoft.XMLHTTP");

    //sending information to server
    function doCall()
        client.onreadystatechange = callBack;"GET", document.getElementById("txtURL").value);

    //waiting and processing server response
    function callBack(response)
            if(client.readyState == 4 && client.status == 200)
<h4>Reading server response Using XMLHttpRequest</h4>
Server URL: <input id="txtURL" type="text" value="HtmlPage2.htm" />
<input type="button"  value="Call" onclick="doCall()" />
<br />[Output]
<hr />
<div id="panel"></div>
<hr />

Create the Second HTML Page

<b>Hello World</b>

Testing the Sample

Try to click that button; you can see "Hello World" text appear in bold, this is actually a response from the server. Try to give other URL in the text box; for example:, you will get an error message "Permission denied." Normally you can't call across the server because it's a security issue, your browser will not allow you to perform this operation. You can call only within a server.

Dynamic Contents

Using the above approach, you can also read a response from any ISAPI applications such as ASP, ASP.NET, PHP, and JSP.

How Does Ajax Use This?

It is really a time consuming job to write JavaScript to call the server, rather than if there is a Framework which does this job for us. This is the reason "Ajax" came to the industry, not only to automate the call, but also to automate everything with a standard and best approach. It creates a JavaScript method which calls our server method, so as developers, we do not need to write any JavaScript for XmlHttpRequest. This is the reason why many people do not know about the classic XmlHttpRequest way.

Does Ajax Create a Bottleneck in the Performance?

Really no. If we use it properly, there is no problem in the performance. We should not do everything on the web using JavaScript/Ajax because it runs on the client side. As a result, we will not have any control as we have on the server.

Please read this article regarding performance problems of Ajax.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author
Web Developer
India India
"Manikandan Balakrishnan" Working as an IT consultant with LogicaCMG’s Global Service Delivery part-India, he has a good experience on Web/Win development (C#, and enterprise application integration (BizTalk) technologies. Prior to this he worked on world’s biggest e-learning product with Excel Soft Technologies, Mysore.

City: Coimbatore, TN

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Md. Mainuddin28-Jan-11 2:07
memberMd. Mainuddin28-Jan-11 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 2 Nov 2007
Article Copyright 2007 by
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid