An example of Ajax partial refresh

Source: Internet
Author: User

Finally, it's a good time.

An example of Ajax partial Refresh:

Front-end page:

 

<% @ Language = "VBScript" codePage = "65001" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Ajax partial refresh </title>
<SCRIPT type = "text/JavaScript">
<! --

// Create an XMLHTTPRequest object
VaR XMLHTTP;
Try {
XMLHTTP = new activexobject ('msxml2. xmlhttp ');
} Catch (e ){
Try {
XMLHTTP = new activexobject ('Microsoft. xmlhttp ');
} Catch (e ){
Try {
XMLHTTP = new XMLHttpRequest ();
} Catch (e ){}
}
}

Function getpart (URL ){
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
If (XMLHTTP. responsetext! = ""){
Document. getelementbyid ("partdiv"). innerhtml = Unescape (XMLHTTP. responsetext );
}
}
Else {
Document. getelementbyid ("partdiv"). innerhtml = "data loading error ";
}
}
}
XMLHTTP. setRequestHeader ("If-modified-since", "0 ");
XMLHTTP. Send (null );
}
Setinterval ("getpart ('getpart. asp ')", 1000)
// -->
</SCRIPT>
</Head>

<Body>
<Div id = "partdiv"> </div> <! -- Partial data refresh container -->
</Body>
</Html>

 

Background page: [getpart. asp]

 

<% @ Language = "VBScript" codePage = "65001" %>
<! -- # Include file = "conn. asp" -->
<%
Dim rs
Dim SQL


Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * From king_test"
Rs. Open SQL, Conn, 1, 1
If not (Rs. bof and Rs. EOF) then
Response. Write ("<Table> ")
Response. Write (escape ("<tr> <TD> id </TD> <TD> keyword </TD> </tr> "))
Do while not Rs. EOF
%>
<Tr> <TD> <% response. write (RS ("ID") %> </TD> <% response. write (escape (RS ("keyword") %> </TD> </tr>
<%
Rs. movenext
Loop
Response. Write ("</table> ")
End if
Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
%>
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.