Fremus.co.za

Demistifying Life and Web Development

What is AJAX? Part2

This article and its contents are based on the articles on the W3C Website, and is a great place to start learning.

AJAX uses the XMLHTTPRequest JavaScript object to communicate directly with the web server and has three important properties:

  • the onreadystatechange property
  • the readystate property
  • the responsetext property

It’s important to note that the XMLHTTPRequest object is not supported by Internet Explorer which uses an ActiveX object, and for that reason when you create an XMLHTTPObject in JavaScript you have to add a few try/catch statements so that it returns the correct object for the correct browser.

If you want to use AJAX on a webpage it is thus important to understand that you need an XMLHTTPRequest object to make it possible. JavaScript is used to create the XMLHTTPRequest object and looks like this:

function GetXMLHTTPObject()
{
     var xmlHttp = null;
     try
     {
          xmlHTTP = new XMLHttpRequest();
      }
      catch(e)
      {
          try
          {
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch(e)
          {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
      }
     return xmlHttp;
}
  • Share/Bookmark
posted by fr3dr1k in AJAX,Web Development,Web Technologies and have No Comments

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment
Get Adobe Flash playerPlugin by wpburn.com wordpress themes