In an online customer service system, Ajax technology is used to achieve no refreshing of information. The following example shows how to regularly clean offline customers.
First, register in the load event
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Ajax. Utility. registertypeforajax (typeof (project. www. SC. guesttalk); // The class name is registered here.
}
// ============ Server event, which is sent by the webpage client ==================
/// <Summary>
/// Clear the user who has been in the activity for 20 minutes
/// </Summary>
/// <Returns> </returns>
[Ajax. ajaxmethod (Ajax. httpsessionstaterequirement. readwrite)]
Public String clearguest ()
{
Dakingconfig = config. getsettings ();
Foreach (datarow drguest in global. dtguestlist. Rows)
{
Timespan Ts = system. datetime. Now-convert. todatetime (drguest ["activetime"]);
If (TS. Minutes> = convert. toint32 (dakingconfig. Timeout ))
{
Global. dtguestlist. Rows. Remove (drguest );
Datarow [] drguesttalks = Global. dtchatlist. Select ("guestid =" + drguest ["guestid"]. tostring ());
Foreach (datarow drtalk in drguesttalks)
{
Global. dtchatlist. Rows. Remove (drtalk );
}
}
}
Return "true ";
}
// ========================= Webpage client request code ============================
<Script language = "JavaScript">
VaR talks = Document. getelementbyid ("Talks ");
// Talks is the tag on the webpage, used to display the string returned by the request
Function POP ()
{
Talks. innerhtml = guesttalk. gettalks (). value;
Guesttalk. clearguest ();
}
// Automatically refresh once every 20 seconds and obtain data once every 20 seconds.
Timer = Window. setinterval ('pop () ', 20000 );
</SCRIPT>