1. First of all, XMLHttpRequest have idiotic API. onreadystatechange
handler have no parameters! (Thanks to Microsoft) So if you have more
then one request on same page for different resources you need to have
separate handler for every request because event handler have no way to
determine which exactly object calls it.
2. It's impossible to have separate handler for every request if you
have variable amount of resources to request (for example tree with
dynamically requested branches). Thanks God javascript was developed by
wise programmers so in normal browsers this problem is solved using
javascript closures.
3. But in IE this is impossible due memory leak. IE garbage collector
can't remove circular references, and this problem is not solved even in
IE7. (Thanks Microsoft again)
4. So we have to make separate component called like 'AjaxChannel'
implementing queue of requests and other components must transfer data
throw it's API.
5. IE don't support readyState==3 so you can't use technique of endless
connection for server-generated events. You need to close down
connection after every server event and reopen it again after processing
data because in IE data will be available ONLY on readyState==4. One
more thank to Microsoft.
6. IE don't support national encodings in XMLHttpRequest so if you have
non-english site you have to use UTF-8 only. If site MUST BE in any
national encoding (like cp-1251 as in my case) you have to implement
recoding routines in javascript and PHP to convert your_site_encoding
<-UTF-8. BIG thanks to Microsoft.
7. After all I recommend to make additional shutdown like this
(specially for IE again):
<script type="text/javascript" for="window" event="onunload">
// Hack for IE
try{downAjax.abort();}catch(e){}
downAjax=0;
</script>
downAjax is the XMLHttpRequest object. Do it for every XMLHttpRequest
object used.
Have nice ajax! :)