hi all.

i'm super-new to ajax.

i got a good book, and there are a lot of examples.

however, the author don't really explain how to use XMLHttpRequest in a real application, where the user will do several things at the same time.

my question is: for each request, you have to create a separate XMLHttpRequest, right?

because on the book they showed this code:

Code:
var xmlHttp;

function createXMLHttpRequest() {

  if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }

  else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  }

} // function createXMLHttpRequest
and this is fine if on the page there is only one request, as they create a global var XMLHttpRequest.

However, I thought that it could happen that there are many requests at once (like if the user, while it's waiting for the first request to be completed, continues doing stuff, starting another request).

So, I changed it to this:

Code:
function createXMLHttpRequest() {

var xmlHttp;

  if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }

  else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  }

return xmlHttp;

} // function createXMLHttpRequest
and for each call I do:

Code:
var xmlHttp1 = createXMLHttpRequest();
var xmlHttp2 = createXMLHttpRequest();
// etc...
is this the right way to go?

thanks!