The XMLHttpRequest Reuse Dilemma - Better Solution
Well I got a few emails asking if I was drunk when I wrote my post yesterday. They said you do not have to use the abort method. One nice person Pavan Keely posted on his blog here: http://keelypavan.blogspot.com/2006/03/reusing-xmlhttprequest-object-in-ie.html on my problem.
In general if I would reverse two lines of code, IE does not need the abort() method. So the example below is a modified version of the bad one I posted yesterday.
What is different with this is that the open method has to be declared before the onreadystatechange as seen below.
if(req){
req.open("GET", url, true);
req.onreadystatechange = processReqChange_IE;
req.send("");
}
So make sure you declare the open first and then the onreadystate after it! Thanks everyone for showing me the light!
There is only on question that is still on my mind and is does the abort() method help with memory leaks or does it make it no difference to reuse the object in this manner. Guess in the future I am going to be doing some testing on my poor tablet.
Eric Pascarello
Coauthor of Ajax In Action
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages