reusing xmlhttprequest objects in IE
Ok, just ran into this so I thought I'd jot it down.
Basically, I have some ajax code I threw together to be able to reuse xmlhttprequest objects. That way I'm not constantly creating new ones and chewing up memory/time.
I built most of this in FF and it worked great, since I can use firebug to debug js issues. Tested it in IE7 and the first request worked... then the second request did nothing. I debugged it pretty heavily and found I was sending the ajax request on the second attempt, but the onreadystatechange event handler was never firing. I was very, very confused.
I did learn some neat things in the process, but it turns out in IE you need to define your onreadystatechange event handler AFTER you call the XMLHttpRequest.open method. For other reason, you also have to define it before you call the XMLHttpRequest.send method. My problem is I was defining the even handler before the open.
In the end I ended up with code similar to this (trimmed for brevity)