Nice AJaX Pattern

Here is a nice AJaX pattern:

In most samples that I have seen so far, a global XMLHttpRequest variable is declared, since you cannot pass variables to the action handler.

In this article, they show a nice pattern, where you declare an anonymous function that calls another named function which may accept parameters; like this:

    http_request.onreadystatechange = function(){
        do_the_thing(http_request);
    };

This is particularly useful if you need to send of multiple XHRs without being able to gurantee the order in which they return.

Thanks to Joan Morris DiMicco for finding this.

Leave a Reply

Your email address will not be published. Required fields are marked *