Two real-time data update examples with no refreshing display

Source: Internet
Author: User

Because of the need for refreshing new data for a website recently, I checked some information on the Internet. The implementation of refreshing new data is almost achieved using JavaScript, XMLHTTP or IFRAME. Finding a code on the internet is neither useless nor inefficient. Some even make my CPU reach 100%. I checked some information based on the Code on the Internet, the following two examples are provided to ensure no errors!

Example 1:
Example1.htm
-------------------------------------
<HTML>
<Head>
<Title> refreshing </title>

<Script language = "JavaScript" type = "text/JavaScript">
Function getdata (URL)
{
Url = "example1.asp"; // call page
Try
{
Dataload. src = URL;
}
Catch (E)
{
Return false;
}
{
VaR timeoutid = setTimeout ("getdata ()", 1000)
}
}
</SCRIPT>
<SCRIPT id = "dataload" Language = "JavaScript" type = "text/JavaScript" Defer> </SCRIPT>

<Body onload = "javascript: getdata ();">
<Span id = loadcontent> loading data ...... </Span>
</Body>
-------------------------------------
Data calling program: example1.asp
--------------------------------------
Loadcontent. innerhtml = "<% = now () %>"

Example 2:
Example2.htm
-------------------------------------
<HTML>
<Head>
<Title> refreshing </title>

<Script language = "JavaScript">
Function getdata ()
{
Url = "example2.asp"; // call page

VaR HTTP = new activexobject ("Microsoft. XMLHTTP ");
HTTP. Open ("get", URL, false );
HTTP. Send ();
VaR STR = http. responsetext;
Loadcontent. innerhtml = STR;
SetTimeout ("getdata ()", 1000 );
}
</SCRIPT>

</Head>
<Body onload = "javascript: getdata ();">
<Span id = "loadcontent"> loading data ...... </Span>
</Body>
</Html>
-------------------------
Data calling program: example2.asp
---------------------------
<% = Now %>
---------------------------

The preceding <% = now %> is just a simple example. Do not mistake it as a program that shows time, for example, you can use these two examples in real-time scores or other data that requires immediate updates. You only need to replace <% = now %> with other programs, of course, you can also use PHP or JSP programs to call data.
I personally think the two examples above are the most concise and recommendable. If you have a better solution, please contact me!

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.