1

I am using long polling in my project. When the project is running, one of the long polling requests is waiting response from the server. Now, when the user generates a new template, then I have to abort the previous long polling call and run the new one.

Aborting in IE gives the error

couldn't complete the operation due to error c00c023f 

I don't want to use the Jquery and aborting the previous request is very important. I tried Try and Catch to prevent from showing this error but it didn't work out.

I am also using the abort when the normal request(not polling request) request doesn't reach the server after few seconds, then I abort the old request and send new one.

I store the xmlHttp object in array for each request.

like: array_XMLHttp.push(request1);

I abort it like: array_XMLHttp[index_of_request].abort();

I couldn't find any solution for IE9, while it works perfect on all other browsers.

UPDATE:

I always check the status and readyState for the XMLHttp Object as below:

function checkResponse(xmlHttp){
    xmlHttp.onreadystatechange=function(){ 
        if(xmlHttp.readyState==4){
            if(xmlHttp.status==200){   
                // Request received
            } 
        }
    }
}      


Here is how I start the request

// to start new XmlHttp object
var xmlHttp=crXH();         

// add the request to array to be aborted later if required
array_XMLHttp.push(request1);

// initiate the callback
checkResponse(xmlHttp);

//send the request to server
send(xmlHttp);


When I abort:

// The problem now the callback function will not read (undefined) the new property added to the aborted object.
array_XMLHttp[index_of_request].aborted = true; 
array_XMLHttp[index_of_request].abort();

Thank you for your help!

15
  • 1
    Possible duplicate: stackoverflow.com/questions/7287706/… Commented Jun 24, 2014 at 0:11
  • 1
    Possible work-around: answer.techwikihow.com/368561/… Commented Jun 24, 2014 at 0:13
  • 1
    There's a lot written about error c00c012f and Ajax abort in IE. A google search shows hundreds of posts. From what I can tell, the common theme is the work-around shown in this article: enkeladress.com/article/internetexplorer9jscripterror. The issue is once you abort, IE triggers onreadystatechange, but it may thrown an exception if you try to access common properties on the object like .readyState or .status. The work-around is to set your own .aborted property when you abort and check that first to avoid checking the other exception-throwing properties on an abort. Commented Jun 24, 2014 at 0:39
  • 1
    You haven't included enough of the relevant code for me to understand what you're asking for help with. You put the .aborted property on the xmlHttp object when you call .abort() which you have to have access to at that time and you also have access to in checkResponse() which are the two places you need it. Commented Jun 24, 2014 at 2:14
  • 1
    Objects like the xmlHttp object are not passed as copies. So, the object that you see in your callback is the exact same object as exists everywhere else. It doesn't matter that it's passed as an argument to a function. That function argument still points to the original object and should show the property. Did you actually try it? Commented Jun 24, 2014 at 2:37

1 Answer 1

1

Codifying our long discussion into an answer...

Per various articles like this one I've found on this topic (it's not an unusual issue in IE), IE does not like you to access the standard properties on the xmlHttp object after you call .abort(), but it will still trigger some onreadystatechange events which causes you to try to access those standard properties, thus causing an error.

The work-around is to set your own property on the xmlHttp object when you call .abort() and in your readystatechange handler, you first check your own .aborted property and if it's set, you then know the call has been aborted and you don't check the other properties which can cause the problem.

So, if your xmlHttp object is called x, then you'd do this:

x.readystatechange = function() {
    if (!x.aborted) {
        if(xmlHttp.readyState==4){
            if(xmlHttp.status==200){   
                // Request received
            } 
        }
    }
}

And, when you want to abort:

x.aborted = true;
x.abort();
Sign up to request clarification or add additional context in comments.

1 Comment

It works like a charm! Thank you very much for helping me with this solution. Appreciate the great hints provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.