XMLHttpRequest error in IE, works without issue in Chrome/FF

Posted by culov on Stack Overflow See other posts from Stack Overflow or by culov
Published on 2010-05-17T03:27:10Z Indexed on 2010/05/17 3:30 UTC
Read the original article Hit count: 311

function addRequest(req) {
try {
    request = new XMLHttpRequest();
} catch (e) {
    try{
        request = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){        
        try {
            request = new ActiveXObject("Microsoft.XMLHttp");
        } catch (e) {
            alert("XMLHttpRequest error: " + e);
        }
    }
}
request.open("GET", req, true);
request.send(null);
return request;

}

As you can see, it IE apparently fails all 3 ways in which I try to make the request. I've been doing plenty of searches to try and find what may be the issue, but by all accounts ive read, the code ive posted above should work.

i havent used jquery for AJAX, but ive seen it recommended when others have had issues with httprequest objects. could i just replace the mess above with a couple lines of jquery and assume that it will take care of IE's ugliness?

Thanks!

© Stack Overflow or respective owner

Related posts about internet-explorer

Related posts about AJAX