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