Weird Thoughts From Eric's Head

Categories : All | AJAX | BUSINESS | PERSONAL | PROGRAMMING | BOOK REVIEW

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


Thank you. This helps a lot.


Add a comment

Title
Body
HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
Math Quiz 6 + 6 = (Helps stop blog spam)
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://radio.javaranch.com/pascarello/addTrackBack.action?entry=1143817890773