Creating the XMLHTTPRequest Object | JavaScriptSource

Creating the XMLHTTPRequest Object

Phil Ballard Jun 23, 2006

General

Many browsers allow the XMLHTTPRequest object to be created directly. One method is to use this snippet. It tries all methods of creating the object until it discovers one that works.

Notes

Microsoft's Internet Explorer uses ActiveX to create the XMLHTTPRequest object, whereas other borwsers — notable the Mozilla/Firefox range — allow the object to be created directly.

There are several ways of tackling this issue, some using browser detection routines (or tools such as BrowserHawk), others taking an approach similar to the following code, which tries all methods of creating the object until it discovers one that works.

See also the basic description of the XMLHTTPRequest object here and a more detailed discussion here.

Source Code

Paste this source code into the designated areas.

Snippet

Paste this code into your script.


Leave a Response

(5 comments)

You will need to submit your question to the [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=3"]JavaScript Forum[/a] for further help.

Lee Nov 7, 2007

You can find it [a href="http://www.barelyfitz.com/projects/tabber/"]here[/a]

Lee Oct 26, 2007

the tab navigation bar at the top of this message. Is there a Javascript to write this or is it AJAX.

Frank G Buck Oct 24, 2007

this script does not work[br /]plz! help me[br /][br /]Thank you

santosh Oct 12, 2007

I am not being able to create XMLHTTPRequest[br /]object using your code[p]please Help me.[p] Thanks in Advance

Biswajit Mar 21, 2007