Re: Simple Ajax



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
.



Relevant Pages

  • VIA SATA Raid needs a long time to recover from suspend
    ... Then if there was an IO request made immediately after resuming, ... Changing the timeout resolved this. ... finally did clear) it would timeout and fail. ... It seemed the kernel ...
    (Linux-Kernel)
  • Re: Problems with the block-layer timeouts
    ... clear a idea of when the timeout period should begin. ... Each request has its own timer, and as it is added to the queue, we ... What the driver chooses to do with the ...
    (Linux-Kernel)
  • Big Uploads with IIS 6.0
    ... I've already posted this question on the IIS forum, ... I have an ASP.NET application that does big uploads on ... upload fails randomly (as if the server had given up on the request). ... timeout in the web.config file, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Problems with the block-layer timeouts
    ... clear a idea of when the timeout period should begin. ... Each request has its own timer, and as it is added to the queue, we ... Requeuing ...
    (Linux-Kernel)
  • Re: Timeout errors using Net::HTTP on Windows
    ... Since this weird Net timeout issue has a solution now, ... Be careful not to have too many threads request from ... def rbuf_fill ...
    (comp.lang.ruby)