Automatically update data in real time with XMLHTTP without refresh

Source: Internet
Author: User
Tags split
xml| Data | refresh | No refresh Traditionally, we browsed the Web page if we added the latest data. It can only be displayed when we re requesting a server-side request.
However, for some time-sensitive websites. The traditional approach is not satisfying.

We can get the program to refresh automatically. Request data to the server on a regular basis. 5 Seconds to take the data, 10 seconds to take the data.
Use XMLHTTP to issue requests and obtain data. Upload to client, client to organize and display data.

<scriptlanguage= "JavaScript" >
Functiongetresult ()
{
/*
*---------------GetResult ()-----------------
*getresult ()
* Function: Send the request through XMLHTTP, return the result.
* Parameters: str, string, send condition.
* Example: GetResult ();
*---------------GetResult ()-----------------
*/
Varobao=newactivexobject ("Microsoft.XMLHTTP");
Special characters: +,%,&,=, etc. transmission solutions. The string is encoded first with escape.
Update:2004-6-112:22
Obao.open ("POST", "server.asp", false);
Obao.send ();

Varstrresult=unescape (Obao.responsetext);

Vararrresult=strresult.split ("###");
Removerow ();

for (vari=0;i<arrresult.length;i++)
{
Arrtmp=arrresult[i].split ("@@@");
NUM1=ARRTMP[0];
NUM2=ARRTMP[1];
Row1=tb.insertrow ();
Cell1=row1.insertcell ();
CELL1.INNERTEXT=NUM1;
Cell2=row1.insertcell ();
cell2.innertext=num2;
}
}

Functionremoverow ()
{

Varirows=tb.rows.length;
for (vari=0;i<irows-1;i++)
{
Tb.deleterow (1);
}
}

Functionmyshow ()
{

Timer=window.setinterval ("GetResult ()", 2000);
}
</script>

<body>
<p>
</p>
<tablewidth= "47%" height= "border=" 0 "cellpadding=" 1 "cellspacing=" 0 "id=" TB ">
<tr>
<td>num1</td>
<td>num2</td>
</tr>
</table>


<% @Language = "JavaScript"%>
<%
FUNCTIONOPENDB (Sdbname)
{
/*
*---------------opendb (sdbname)-----------------
*OPENDB (Sdbname)
* Function: Open database Sdbname, return conn object.
* Parameters: Sdbname, String, database name.
* Example: Varconn=opendb ("Database.mdb");
*---------------opendb (sdbname)-----------------
*/
Varconnstr= "provider=microsoft.jet.oledb.4.0;datasource=" +server.mappath (sdbname);
Varconn=server.createobject ("ADODB.") Connection ");
Conn. Open (CONNSTR);
Returnconn;
}
Varsresult=newarray ();
Varoconn=opendb ("Data.mdb");
Special characters: +,%,&,=, etc. transmission solutions. The client character is encoded by escape
So the server side first to pass through unescape decoding.
Update:2004-6-112:22
Varsql= "Selectnum1,num2fromnumsorderbyid";
Varrs=oconn.execute (SQL);
while (!rs. EOF)
{

Sresult[sresult.length]=rs ("Num1"). Value+ "@@@" +rs ("num2"). Value
Rs. MoveNext ();
}

Response.Write (Escape (Sresult.join ("###"));
%>



Table Nums
ID, automatic numbering
NUM1, text
num2, text

ID NUM1 num2
1 20.70 20.810
2 10.5 20.5
3 12.3 300
4 132 323
5 563 56
6 20 10



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.