Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Why IE11 cant send a POST request by using legacy javascript code and XMLHttpRequest?

$
0
0

Hello everybody,

  When I use IE8, my javascript code can send a request to the web server but when I use IE11 the same request does not exit from the browser.

  I use alternatively two PCs which I connect to an embedded system on the same network. The browser is on the PC and the server on the embedded system. IE11 runs under Windows 7 and IE runs under Win XP. It also works with Chrome under Windows 7.

  The javascript code is identical in both cases because the server did not change (and I emptied the cache of the browser).

  I sniffed the communication, and I noticed that the request (HTTP POST <SetRoadParam> ...) did not even exit from my PC, which was the case with IE8.

  I know that IE9 and + use XMLHttpRequest rather than ActiveX object.

  Here is the partial code:

  function request(/*callback,*/data)

  {
      //var sCmd = encodeURIComponent(command);
      //var sDta = encodeURIComponent(data);
      var xhr = connectToServer();

      // prepare the callback function.
      xhr.onreadystatechange = function()
      {
          if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
          {
              if ( xhr.responseXML != null )
              {
                  parseResponse(xhr.responseXML);
               }
               else if ( xhr.response == "not logged" )
               {
               // force page refresh to move automatically to the logging page.
                   window.location.reload(false);
                }
           }
      };

      xhr.open("POST", "/ajax/messages", true);
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      xhr.send(data);
  }

The call is:  

function setRoadParam() 
{
    var serial = document.getElementById("Serial").value;
    var Vin = document.getElementById("VIN").value;   
    var model = document.getElementById("Model").value;   

    request("<SetRoadParam><SERIAL>"+serial+"</SERIAL><VIN>"+Vin+"</VIN><MODEL>"+model+"</MODEL></SetRoadParam>");

    document.getElementById("ParameterResult").innerHTML= "Status: Vehicule parameters saved"; 
}

Additional source:

function connectToServer()
{
    var xhr = null;
    /*try to connect to the server*/
    var xhr = new XMLHttpRequest();

    if (window.XMLHttpRequest || window.ActiveXObject)

    {

        if (window.ActiveXObject)

        {
            try

            {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
             }

             catch(e)

             {
                 xhr = new ActiveXObject("Microsoft.XMLHTTP");
             }
        }

        else

        {
            xhr = new XMLHttpRequest(); 
         }
    }

    else

    {
        alert("XMLHTTPRequest error 0 : Cannot connect to Server");
        return null;
     }

    return xhr;
}

  I debugged the code under IE11 and I saw that XMLHttpRequest is used rather than ActiveXObject.

  Any idea of the cause?

Thank you!


Viewing all articles
Browse latest Browse all 3527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>