XMLHttpRequest() Not Working with IE

26,722

Solution 1

Below IE7, it uses ActiveXObject objects instead of XMLHttpRequest So your code should be like this:

function postData() {
    var http;

    if (window.XMLHttpRequest) {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         http = new XMLHttpRequest();
    }
    else {
         // code for IE6, IE5
         http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var url = "/scripts/remove_fr.php";
    var params = "";
    http.open("GET", url, true);

   //Send the proper header information along with the request
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");
   http.onreadystatechange = function() { //Call a function when the state changes.
       if(http.readyState == 4 && http.status == 200) {

       }
   }
   http.send(params);
}

Solution 2

Can you try this code , this gets the XMLHttpRequest based on the browser.

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

Please refer link for details w3schools

Share:
26,722
Cookiimonstar
Author by

Cookiimonstar

Updated on July 05, 2022

Comments

  • Cookiimonstar
    Cookiimonstar almost 2 years

    The script below is working fine with Firefox and Chrome but I cant seem to get it to work with ie, tried everything even lowered the security on my browser to see if was that blocking it, but i still cant get it to work.

    function postData() {
    
        var http = new XMLHttpRequest();
    
        var url = "/scripts/remove_fr.php";
    
        var params = "";
    
        http.open("GET", url, true);
    
    
    
        //Send the proper header information along with the request
    
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    
        http.setRequestHeader("Content-length", params.length);
    
        http.setRequestHeader("Connection", "close");
    
    
    
        http.onreadystatechange = function() { //Call a function when the state changes.
    
            if(http.readyState == 4 && http.status == 200) {
    
    
    
            }
    
        }
    
    
    
        http.send(params);
    
    
    
    }
    
    
    
        $("#qwerty").click(function () {
    
          $('#qwerty').remove();
    
        });
    
    
    
    </script>