View Full Version : Multiple AJAX requests

07 Mar 2006, 10:36 PM
I had some problems with a recent AJAX based project. The tutorials I learned about the XMLHttpRequest, the http_request variable was declared globally. The problem I ran into was when multiple functions called the createXMLHttp function. The global variable would be overwritten and the the wrong results would show up in some places.

My first attempt to resolve the single resource issue was to dynamically create http_request variables by using an array.
Multiple XMLHttp Requests 1 (http://www.digitalbonsai.com/index.php?itemid=2)

Still didn't resolve the problem that competing functions were requesting a limited resource. So, instead of using a global variable or array, I declared the http_request variable local to the createXMLHttp function. The calling function, instead of calling createXMLHttp(), it set it equal to a variable. createXMLHttp request passes back the variable and then the calling function may handle the onstatechange and process the result.
Multiple XMLHttp Requests 2 (http://www.digitalbonsai.com/index.php?itemid=5)

I hope this makes sense and helps anyone interested.

digitalbonsai.com (http://www.digitalbonsai.com)