Latest web development tutorials

AJAX XMLHttpRequest object is created

XMLHttpRequest is the foundation of AJAX.

XMLHttpRequest Object

All modern browsers support XMLHttpRequest object (IE5 and IE6 use ActiveXObject).

XMLHttpRequest for exchanging data with the server behind the scenes. This means that without reloading the entire page of a section of the page is updated.

Create XMLHttpRequest object

All modern browsers (IE7 +, Firefox, Chrome, Safari and Opera) are built-in XMLHttpRequest object.

Create XMLHttpRequest object syntax:

variable=new XMLHttpRequest();

Older versions of Internet Explorer (IE5 and IE6) using ActiveX objects:

variable=new ActiveXObject("Microsoft.XMLHTTP");

In order to cope with all modern browsers, including IE5 and IE6, please check whether the browser supports the XMLHttpRequest object. If so, then create XMLHttpRequest object. If not, create ActiveXObject ::


var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

try it"

In the next chapter, you will learn the sending server requests.