10. Other Advanced Controls
Periodically Updating Controls
<< Combining Controls: A Better Way to Upload Files   |   Back to Main   |   Next >>

View Source
will open in a new window
Making Periodic AJAX Calls via a Polling Processor
This example demonstrates how to add Polling (a.k.a. "Periodical Updates") to your QForms. This polling mechanism can be used to simulate a real-time stream from the server to client. Some common use cases include progress bars and web-based chat applications.

We add polling to our QForm by calling SetPollingProcessor in Form_Create, passing in the name (and optionally the parent object) of the user-defined method to repeatedly call, and (also optionally) the polling interval in milliseconds (default is 2.5 seconds). In this example, we are updating the clock below with the current time every second. Clicking the button stops the polling by calling ClearPollingProcessor.

Finally, note that because every polling recurrence involves an HTTP request to the server, care should be taken when setting the polling interval to avoid excessive server load.
The time reported on the server is:
12:33:38 am