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!