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

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 IE does not seem to be able to handle all 3 ways I am trying to fulfill the request. I did a lot of searching to try and find what might be the problem, but for all accounts ive read, the code shown above should work.

i havent used jquery for AJAX but saw what it recommended when others had problems with httprequest objects. can I just replace the mess above with a couple of lines of jquery and assume it takes care of IE's outrage?

Thanks!

+2


a source to share


2 answers


i havent used jquery for AJAX but ive seen it recommended when others have problems with httprequest objects. could i just replace the mess above with 2 lines of jquery and assume it takes care of IE ugliness?

The short answer is yes.

Although the jquery syntax does things differently, so you won't be explicitly creating the request and submitting it. Its all wrapped in a function. For instance. from http://api.jquery.com/jQuery.get/



$.get("test.cgi", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });

      

You can forget about browser interaction issues. As long as you keep up to date with jquery releases :) love it

+5


a source


Different versions of IE have different ways of accessing the XMLHTTP object.

It is linked to the MSXML libraries installed on your computer. What OS / IE version are you using?



Try running Windows Update. Odd solution, but that might work here.

+1


a source







All Articles