AJAX concurent queries

R

Ralph

Hi

How can I make several asynchronous XMLHttpRequest queries?

The one thought I have is to have few XMLHttpRequestObjects and send
queries using them alternately. But what if i don't know how many
queries I need to send? (btw: I know only which handler functions must
be used to handle the queries' response).

Does any one know where to look for answer to this problem or maybe
someone have some code snippets i could learn from.
 
B

Bas Cost Budde

You could put all requests in a Container object, storing the actual
request objects in some array, and upon receipt of 4/200 kill the entry
with array.splice(). The Container would need to expose only .Request as
a public method, I think.

Have you had a look into www.twilightuniverse.com?

Ralph schreef:
 
R

Ralph

Matt Kruse wrote:

Thank you very much for response I went over the code and I have one
question:

In one of your examples you are making simultaneous queries using the
function like this:

AjaxRequest.get(
{
'url':'sleep.pl'
,'onSuccess':function(req){ target.value=req.responseText; }
}
);

In this snippet you are defining function what to with responseText. Is
it possible to declare handling function somewhere else (lets say within
different file and call it like this:

AjaxRequest.get(
{
'url':'sleep.pl'
,'onSuccess':my_handler(req)
}
);

That would allowed me to use my existing functions to handle responses.
 
M

Matt Kruse

Ralph said:
Is it possible to declare handling function somewhere else (lets say
within different file and call it like this:
AjaxRequest.get(
{
'url':'sleep.pl'
,'onSuccess':my_handler(req)

Of course, but it would be
'onSuccess':my_handler

Writing it like you have done would call my_handler at the time of the
AjaxRequest.get() function call, and assign its result to the onSuccess
attribute.
 
P

pcx99

Most of the javascript tutorials are pretty horrible when it comes to
concurrent queries. The solution is to set up an object. It's one of
the first things I did when I started tinkering with my site, and I
actually wrote an article documenting it just to help test the site out.
You can snag the code (use freely) at http://www.hunlock.com

Once set up you can define new handlers on demand (and destroy ones no
longer in use), you can even have an array of them.

Good luck, and hope this is what you're looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top