Re: Simple Ajax
- From: Diego La Monica <diego.lamonica@xxxxxxxxx>
- Date: Wed, 19 Nov 2008 12:26:59 -0800 (PST)
With setInterval you poll the server every 2 seconds (0, 2, 4, 6 etc.
etc.).
That is definitely _not_ what happens. Have you not even understood your
own code?
Ok I've served you as is... I try to explain better my code: the poll
try to start (if any other request is stil active) every 2 seconds.
I cite the Brian's question:
<cite>
Is there a way to add a timeout to this script so that it times out
at
a certain time. So it would be auto updating every 2seconds and it
would timeout like after 100 seconds with a message?.
</cite>
"...auto updating every 2 seconds..."
My interpretation is that every 2 seconds should start the ajax_update
method, your interpretation is that after 2 second since the last
execution ajax_update method should start. Well are 2 Point of view
differents! I'm not stating you're wrong... You, instead, do it.
With setTimeout you poll the server every 2 seconds + server response
lag (0, 2+[time to response 1], 4+[time to response 2], and so on).
Nonsense. The next request is made, through calling the called method
again, 2 seconds after the previous one was finished (successfully or
otherwise), not before. And that is good so.
I don't think is good so.
Test case with your consideration:
in the following: "request" is the times that xhr.open is called,
"response" is the the readyState=4 of xhr object.
- 1st client request: 0,00 (start point)
- 1st server response: 1,87 seconds (then wait 2,00 seconds)
- 2nd client request 3,87 seconds (result of 1,87 + 2,00 of timeout)
- 2nd server response: 1,99 seconds (then wait 2,00 seconds)
- 3rd client request: 7,86 seconds (result of 3,87 +1,99 +2,00
seconds)
- 3rd server response: 3,00 seconds (then wait 2,00 seconds)
- 4th client request: 12,86 seconds (result of 7,86 +3,00 +2,00
seconds)
.... and so on!
Test case with my alghoritm:
- 1st client request: 2,00 (start point)
- 1st server response: 1,87 seconds
- 2nd client request: 4,00
- 2nd server response: 1,99 seconds
- 3rd client request: 6,00
- 3rd server response: 3,00 seconds
- 4th client request: 10,00
.... and so on!
Let decide bryan which is what he want... or Bryan and you are the
same person?
The abort should be called only if something goes wrong not every 100
seconds
That is in your imagination, though, not in the OP's specification.
bryan wrote: "...auto updating every 2seconds and it would timeout
like after 100 seconds..."
It's in the Bryan request not in my imagination.
else you risk to abort a request started just few seconds before.
Yes, a condition needs to be implemented in the function used in the
window.setTimeout() call after send(), to prevent that.
However, the OP's specification says to cancel the request after that time
*no matter what*.
Sure? Bryan wrote: "...it would timeout like after 100 seconds with a
message?. "
So matter what. Or did I read it wrong?
And even if we extend the original specification like you
interpreted it, it still does not call for using window.setInterval() with
that rather bogus approach of yours.
mmm... Yor are going again to make this post a flame. Please, be
professional as I think you are and weight one's word. If you proceed
again on this way I will stop to discuss with you!
Regards!
Diego La Monica
.
- Follow-Ups:
- Re: Simple Ajax
- From: Jorge
- Re: Simple Ajax
- References:
- Simple Ajax
- From: Bryan A
- Re: Simple Ajax
- From: Diego La Monica
- Re: Simple Ajax
- From: Thomas 'PointedEars' Lahn
- Re: Simple Ajax
- From: Diego La Monica
- Re: Simple Ajax
- From: Thomas 'PointedEars' Lahn
- Re: Simple Ajax
- From: Diego La Monica
- Re: Simple Ajax
- From: Thomas 'PointedEars' Lahn
- Re: Simple Ajax
- From: Diego La Monica
- Re: Simple Ajax
- From: Thomas 'PointedEars' Lahn
- Re: Simple Ajax
- From: Diego La Monica
- Re: Simple Ajax
- From: Thomas 'PointedEars' Lahn
- Simple Ajax
- Prev by Date: Re: When to minify?
- Next by Date: Re: When to minify?
- Previous by thread: Re: Simple Ajax
- Next by thread: Re: Simple Ajax
- Index(es):
Relevant Pages
|