How to Create XMLHTTP object

How to Create XMLHTTP object

Before we start to code in ajax, we should know how to create XMLHTTP object. For example if we create like this
http_request = new XMLHttpRequest();

It will work only in mozila type browsers, it won’t work in IE..

Following code will show you how to create XMLHTTP object,

if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType(’text/xml’);
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject(”Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(”Microsoft.XMLHTTP”);
} catch (e) {}
}
}

In the above code if block is used to create object for mozila type browser.

Then the else block shows how to create an object for IE browsers.

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.