Recently, this module is used to query the log system in real time.
The idea is: 1. When loading a webpage, read X records from the database and display them on the page. 2: Set the refresh time, dynamically read records from the database, and perform
Partial refresh. Because it is a partial refresh, Ajax technology is used.
The specific method is:
1: Download Ajax. dll dynamic connection library from the website http://ajax.schwarz-interactive.de/csharpsample/default.aspx.
2: Configure web. config
<System. Web>
<Httphandlers>
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
</Httphandlers>
</System. Web>
3: add the following to the webpage: Code
<Head>
<Script language = "JavaScript" src = "ajax/common. ashx"> </SCRIPT>
<Script language = "JavaScript" src = "ajax/ajaxwebapp. Demo, ajaxwebapp. ashx"> </SCRIPT>
</Head>
Note: In ajaxwebapp. Demo, ajaxwebapp is the namespace name and demo is a type of name.
4: add the Ajax. Utility. registertypeforajax (typeof (ajaxwebapp. Demo) statement to page_load.
5: start to write the method in the demo class:
Format: [Ajax. ajaxmethod]
Public String getdataset ()
{
// Code for reading data.
Return HTML;
}
6: Call this method in the HTML code of the web page.
<Script language = "JavaScript">
Demo. getdataset (getdataset_callback );
Function getdataset_callback (response)
{
VaR retvalue = response. value;
// Process retvalue code
}
</SCRIPT>
7: Now the basic Ajax operations have been completed.
8: The following is how to dynamically obtain data from the server:
Use JavaScript
Setinterval ("getdata ();", refreshtime );
Change the code in section 6th
<Script language = "JavaScript">
Function getdata ()
{
Demo. getdataset (getdataset_callback );
}
Function getdataset_callback (response)
{
VaR retvalue = response. value;
// Process retvalue code
}
Setinterval ("getdata ();", refreshtime );
// Refreshtime is the custom refresh time
</SCRIPT>
Add the code to process the data!