Link to home
Start Free TrialLog in
Avatar of Abdu_Allah
Abdu_Allah

asked on

Getting rid of Ajax error number 12030 in IE

Hi, As you know there is a bug in IE which send request number 12030 when do ajax request, somebody suggest to get rid from this problem as this one: http://community.xajaxproject.org/viewtopic.php?id=972   (look at the last posting) is to recall the request as follow:
switch(xmlHttp.status){
    case 12029:
    case 12030:
    case 12031:
    case 12152:
    case 12159:
        //repeat call here
}

Now the following is my code, my question is where should I place this Switch block in it and how can I repeat the call:

help please
var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
 
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
 
   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
         
         } else {
            alert('There was a problem with the request. Request Status: ' + http_request.status);
         }
      }
   }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Abdu_Allah
Abdu_Allah

ASKER

I think you mean:

  function alertContents() {
switch(http_request.status){
    case 12029:
    case 12030:
    case 12031:
    case 12152:
    case 12159:
        //repeat call here
makePOSTRequest(url, Oldparameters);// store the paremeters value to a global oldParameters
 
}
 
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
         
         } else {
            alert('There was a problem with the request. Request Status: ' + http_request.status);
         }
      }
   }

Open in new window

I wanted only to repeat the send() Call, but perhaps is your idea better to refresh the complette handle, not only repeat the send() call.
How about placing switch block under http_request.send(parameters); in makePOSTRequest funcrion just to prevent storing parameters?
You cannot do that.
Why?
You cannot do that because you use in upper script the asynchronous call method.

But perhaps are all your problems solved when you switch to synchronous request.
This is synchronous version:
var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      //http_request.onreadystatechange = alertContents;
 
      http_request.open('POST', url, false);  // false: synchronouse
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
            alert(http_request.responseText);
            result = http_request.responseText;
 
   }
 
 
 

Open in new window

Are you sure that will solve the problem because the problem does not appear at our end but at our client's end so we want to send him the update that we are sure it works.
I am NOT sure.
Did you solve your problem?
Not yet
When you have a result it would be kind to publish it here.