Tuesday, 15 July 2014

javascript - Getting an error when aborting AJAX request in IE9 -



javascript - Getting an error when aborting AJAX request in IE9 -

i using long polling in project. when project running, 1 of long polling requests waiting response server. now, when user generates new template, have abort previous long polling phone call , run new one.

aborting in ie gives error

couldn't finish operation due error c00c023f

i don't want utilize jquery , aborting previous request important. tried seek , grab prevent showing error didn't work out.

i using abort when normal request(not polling request) request doesn't reach server after few seconds, abort old request , send new one.

i store xmlhttp object in array each request.

like: array_xmlhttp.push(request1);

i abort like: array_xmlhttp[index_of_request].abort();

i couldn't find solution ie9, while works perfect on other browsers.

update:

i check status , readystate xmlhttp object below:

function checkresponse(xmlhttp){ xmlhttp.onreadystatechange=function(){ if(xmlhttp.readystate==4){ if(xmlhttp.status==200){ // request received } } } }

here how start request

// start new xmlhttp object var xmlhttp=crxh(); // add together request array aborted later if required array_xmlhttp.push(request1); // initiate callback checkresponse(xmlhttp); //send request server send(xmlhttp);

when abort:

// problem callback function not read (undefined) new property added aborted object. array_xmlhttp[index_of_request].aborted = true; array_xmlhttp[index_of_request].abort();

thank help!

codifying our long give-and-take answer...

per various articles one i've found on topic (it's not unusual issue in ie), ie not access standard properties on xmlhttp object after phone call .abort(), still trigger onreadystatechange events causes seek access standard properties, causing error.

the work-around set own property on xmlhttp object when phone call .abort() , in readystatechange handler, first check own .aborted property , if it's set, know phone call has been aborted , don't check other properties can cause problem.

so, if xmlhttp object called x, you'd this:

x.readystatechange = function() { if (!x.aborted) { if(xmlhttp.readystate==4){ if(xmlhttp.status==200){ // request received } } } }

and, when want abort:

x.aborted = true; x.abort();

javascript ajax internet-explorer internet-explorer-9

No comments:

Post a Comment