AJAX IE using Firefox XMLHttpRequest()

I

Iain Adams

My code is as follows.

http_request = false;
if (window.XMLHttpRequest) {
alert("firefox");
http_request = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
alert("ie");
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.open('GET', url + parameters, true);
http_request.onreadystatechange = alertContents;
http_request.send(null);
}

Now I was under the impression that IE didnt have support for
XMLHttpRequest like firefox so thought you had to do it this way. But
this code works in firefox and alert says firefox. however code doesnt
work in IE and prints firefox in alert
 
M

Martin Honnen

Iain said:
Now I was under the impression that IE didnt have support for
XMLHttpRequest like firefox so thought you had to do it this way. But
this code works in firefox and alert says firefox. however code doesnt
work in IE and prints firefox in alert

IE 7 supports XMLHttpRequest so your check
if (window.XMLHttpRequest)
yields true with Mozilla, with Opera 8 and later, with IE 7, with Safari
(I think 1.2 and later).
Feature check like the above are fine, only you should not use them to
infer a certain browser. All you can infer is that
boolean(window.XMLHttpRequest) evaluates to true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top