T
Tony
I've done a fair bit of searching on this, but I want to be certain
about what I've found - so here goes with a long example and three
questions:
For clarity, let me give an example (a number of the pages I found had
some ambiguity). Say I have a page with 2 buttons ( A and B, for
simplicity) and each button will make a different "ajax" request, for
data to be placed in a corresponding DIV.
For sake of example, we won't consider latency.
The simple operation, assuming no server-processing time issues: I
click A and it responds with data for DIV A, click B and it responds
for DIV B.
But now let's assume that the processing for A takes 10 seconds, and B
takes 5 seconds. Also assume that I click these buttons at a rate of 1
per second (A, B, in that order).
If I queue the requests, then when I click A, the request takes 10
seconds to process. When I click B, that request has 9 seconds left to
process. So the request for B just sits there for 9 seconds until the
response comes back from A (9 seconds later), THEN the request is sent
out, and I get my response from B 5 seconds after that, or 14 seconds
after I clicked on B.
If I send the requests immediately, then when I click A, it sends out a
request which takes 10 seconds to process. When I click B, there are 9
seconds left for A to process. B is done processing 5 seconds later,
while A still has 4 seconds left. So I should be able to get the
response back from B, then 4 seconds later get the response for A - so
even though A is clicked first, the response for B comes back first.
But I can't seem to make this happen.
Even if I set up a new 'object' (I know JS doesn't have 'real' objects)
and keep the requests tied to each individual object, the second
request cancels the first, so I only get a response to the most
recently made request.
Which leads me to question #1 - How do I make two simultaneous requests
like this? Or can I?
I also have read that users can generally only have 2 connections open
at the same time on one client - which leads to question 2: Is it
better to just forget trying to make simultaneous requests and simply
queue them?
And the final question - if I just queue the requests, how, then, would
that differ from making the requests synchronous?
Thanx for the input...
about what I've found - so here goes with a long example and three
questions:
For clarity, let me give an example (a number of the pages I found had
some ambiguity). Say I have a page with 2 buttons ( A and B, for
simplicity) and each button will make a different "ajax" request, for
data to be placed in a corresponding DIV.
For sake of example, we won't consider latency.
The simple operation, assuming no server-processing time issues: I
click A and it responds with data for DIV A, click B and it responds
for DIV B.
But now let's assume that the processing for A takes 10 seconds, and B
takes 5 seconds. Also assume that I click these buttons at a rate of 1
per second (A, B, in that order).
If I queue the requests, then when I click A, the request takes 10
seconds to process. When I click B, that request has 9 seconds left to
process. So the request for B just sits there for 9 seconds until the
response comes back from A (9 seconds later), THEN the request is sent
out, and I get my response from B 5 seconds after that, or 14 seconds
after I clicked on B.
If I send the requests immediately, then when I click A, it sends out a
request which takes 10 seconds to process. When I click B, there are 9
seconds left for A to process. B is done processing 5 seconds later,
while A still has 4 seconds left. So I should be able to get the
response back from B, then 4 seconds later get the response for A - so
even though A is clicked first, the response for B comes back first.
But I can't seem to make this happen.
Even if I set up a new 'object' (I know JS doesn't have 'real' objects)
and keep the requests tied to each individual object, the second
request cancels the first, so I only get a response to the most
recently made request.
Which leads me to question #1 - How do I make two simultaneous requests
like this? Or can I?
I also have read that users can generally only have 2 connections open
at the same time on one client - which leads to question 2: Is it
better to just forget trying to make simultaneous requests and simply
queue them?
And the final question - if I just queue the requests, how, then, would
that differ from making the requests synchronous?
Thanx for the input...