Using ExtJS development MIS System (4): Polling

Source: Internet
Author: User

As we all know, HTTP is stateless, and each time the request is finished, the client disconnects from the server side. Requests are always initiated from the client, and the server side has no way to actively deliver any data to the client unless the client initiates the request. However, for MIS, it is often necessary to push data from the server side to the client, for example, when the user submits a new request, the administrator needs to approve it. The solution is the client "perseverance" to ask the server, whether there are new things to do, that is, the so-called polling technology.

The polling process can be described in the following diagram:

We still take the user login as an example, first look at the polling process:

Each time a user successfully logs on, the server side will issue an identity token to the client, which is a GUID.

The client initiates a request to the server each minute to report the current user login token.

After the server obtains the token, it verifies the user's logon information and, if the user's logon information is valid, updates the user's last activity time, and then returns the information that the user is currently logged in, or returns an error.

The client resolves the login information.

If the token is invalid, such as the user is locked or deleted by the administrator, and so on, the report login failure, jump login interface. otherwise do nothing.

This makes it possible to:

Any changes in user information will be reflected in a timely manner, such as when the user receives a new system short message, and the next time the client polls, there will be a report.

Administrators can manage the user login status, more accurately view the current logged-in user or kick out the user and so on.

In fact, the basic purpose of polling is to make the server side more accurate about the client state, and also the opportunity to tell the client what to do, which simulates a two-way request link.

Using ExtJS to implement polling is very easy, built-in ext.taskmgr encapsulates setinterval,clearinterval, such as the above polling can be implemented using the following code:

1: Srims._activeTask = {
2:   run: function(){
3:     var token = Srims.currentLoginLog.token;
4:     if (token == undefined)
5:       Srims.currentLoginLog.token = Cookies.getToken();
6:     Ext.Ajax.request({
7:       url: '/User.asmx/Active',
8:       success: Srims._onActive,
9:       method: 'POST'
10:     });
11:     
12:   },
13:   interval: 1000 * 60
14: }
15: Ext.TaskMgr.start(Srims._activeTask);

You can refer to the two classes Ext.taskmgr and Ext.util.TaskRunner in the ExtJS documentation for detailed instructions.

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.