This article is a spanzhang original, its blog address is: http://blog.9cbs.net/spanzhang. Quote or repost, please indicate the source, thank you! !
To showcase data as the main task, such as stock classes, you want to display data in the database in real time. The popular solution is to make the data into an XML format, and the browser takes the XML data over a period of time and then updates to the web. One is to use Microsoft.xmlhttp to get data from the server, the other is the data on the load server with msxml2.domdocument. These two methods are almost, all of which are walking XML routes. [Menciic E Chapter] Write a lot of articles in this mode, and it will not be discussed here. I focus on the incremental update process of the data. Suppose our data is a two-dimensional relational data, and each line has a primary key uniquely indicated. The web server starts a server clock in Application_Start, updating the data every other time. The server provided to the client's XML data contains two files, one is all the data of the current version (all.aspx), and the other is the current version and the incremental data of the previous version (Delta.aspx). The source code is as follows: ALL.ASPX file: <% @ page language = "c #"%> <% response.expires = 0; response.contentType = "text / xml"; response.charset = "UTF-8";%> <% System.data.dataable DT = SM_Web.logic.dt_all;%> > <% IF (dt! = Null) {for (int i = 0; I " b = "<% = DT.ROWS [i] [" b " ]%> "c =" <% = dt.rows [i] ["c"]%> "d =" <% = DT.ROWS [i] ["D"]%> "/> <%}} %> r> where sm_web.logic.dt_all and sm_web.logic.Dataversion are static variables.
An example of the generated XML data is as follows: / dDelta.aspx file: <% @ page language = "c #"%> <% response.expires = 0; response.contenttype = "text / xml"; response .Charset = "UTF-8";%> > <% = SM_Web.Logic.ChangeDXML%> r> where sm_web.logic.changedXML is static variable. The generated XML data is shown, for example,: r> Here, A is a tag field to indicate the type of update to a row of data, from: 0: None; 1: Modify; 2: Delete; 3: Increase. The XML is all in the way of the properties indicates that the data is to reduce network transmission, because A = "" ratio is 3 characters less. The server clock will be processed each step: 1, acquire all of the current data; 4. SM_Web.logic.DataVersion increases 1. The process of processing the entire server is like this. And in the client, the page is simultaneously downloading all.aspx content, and initializes all page elements (including a client data version number) and opens a clock to be less than half of the server-side clock speed. The speed step of small little bit (as for why, discuss it later). Every time you clock, you need to do the following steps: 1, stop clock step into; 2, download Delta.aspx asynchronously; after Delta.aspx download is complete, judge the version number of new data: 1, if and the current client The data version number is the same, then start the clock and returns; 2. If the version number is more than the current client data version number 1 (version number break), resynchronize the ALL.ASPX, start the clock after the data is updated; 3 Otherwise, to process the incremental data, update the local element of the web page. The above operation is placed in a TRY block and restarts the client's clock after completion. It is necessary to set it carefully for the clock update speed of the server and the client's clock update. Since the client needs to reload all the data in the case of the version number break, do not set the client's time to be too long, at least a small bit more than half of the server-side clock (consider network delay). However, it is not too small that the client has lost time with the user's interaction. In one of my applications, the server-side clock update speed is 4 seconds, and the client update speed is 1 second, which can guarantee that the version number break will not occur.