Skip to main content
100%

Simple Long Polling Example with JavaScript and jQuery by Tian Davis (@tiandavis) from Techoctave.com (http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery)

✓ Published0🌍 Public
Aamoradi
Last edited Oct 4, 2016
Created on Oct 4, 2016

This example demonstrates three polling techniques for updating a sales dashboard gauge with server data. It shows long polling using jQuery’s `$.ajax` with a `complete` callback that immediately re-issues the request, creating an open connection for fast updates, while also handling Firefox’s timeout quirk via `setTimeout`. In contrast, recursive polling uses `setTimeout` to schedule a new AJAX call after each response, and traditional polling relies on `setInterval` to fire requests every 30 seconds. All three use `dataType: "json"` and call `salesGauge.setValue(data.value)` on success, with the animation visible as the gauge updates.

AI-generated description

Similar vizzes