Use ajax to make a real-time log system query module and communicate with interested peers!

Source: Internet
Author: User

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!

Related Article

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.