Common Ajax skills-automatically refresh the page.

Source: Internet
Author: User
The web page auto-refresh function is already common on the web site, such as instant news and stock information. In the traditional web implementation mode, to achieve similar effects, you must refresh the entire page. When the network speed is limited, this... syntaxHighlighter. all ();

The web page auto-refresh function is already common on the web site, such as instant news and stock information. In the traditional web implementation mode, to achieve similar effects, you must refresh the entire page. When the network speed is limited, this method affects the processing of the entire page due to a local change. The emergence of Ajax solves this problem well. Ajax technology can be used to partially refresh webpages, only update specified data, and not update other data.
Create an instance to demonstrate the automatic refresh function of the webpage. This instance simulates Subtitles displayed in the train ticket hall.
1. server code

The server-side code function of this instance is simple, that is, a random number is generated and returned to the client in the form of an XML file. Open notepad and enter the following code:
<% @ Page contentType = "text/html; charset = gb2312" %>
<%
Response. setContentType ("text/xml; charset = UTF-8"); // set the format and Character Set of the output information
Response. setHeader ("Cache-Control", "no-cache ");
Out. println (" ");
For (int I = 0; I <2; I ++ ){
Out. println (" "+ (Int) (Math. random () * 10) +" ");
Out. println (" "+ (Int) (Math. random () * 100) +" ");
}
Out. println (" ");
Out. close ();
%>
 

Save the preceding code named auto. jsp. In this file, use the Math class in the java. lang package to generate a random number.
2. client code

The client code of this instance mainly uses the numbers returned by the server to specify the display style. Open notepad and enter the following code:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "GBK" %>



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.