Hussain
Hussain

Reputation: 663

How Long Polling in AJAX works

I asked a previous question about keeping up a constant link with a database, and someone suggested long polling. I found a small tutorial with a skeleton, but I don't understand some things. The page is here: https://web.archive.org/web/20120306031249/http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=575

First, what happens after 30 seconds? Does it quit? Second, why does it sleep if there's no new content.

Upvotes: 0

Views: 417

Answers (2)

jspcal
jspcal

Reputation: 51914

In that example, the loop in the server script will iterate no more than twice. So the request won't be open too long.

You could just as well do the sleep on the client side.

It makes sense to poll at an interval so that you don't put too much load on the underlying resource being queried.

Upvotes: 0

Kendall Hopkins
Kendall Hopkins

Reputation: 44104

I think your interested in Comet Programming, which is a simulation of a two way socket using http (ajax). This link should help answer your questions. http://en.wikipedia.org/wiki/Comet_(programming)

Upvotes: 1

Related Questions