xml| Data | refresh | no refresh
Some time ago wrote several examples about the use of XMLHTTP.
(You can go to http://dev.csdn.net/user/wanghr100 to see some of the previous series on XMLHTTP introduction.)
Recently, the forum is often asked questions about how no refresh, Automatic Update data.
Traditionally, we browse the Web and if we add the latest data, we can only display it when we re requesting it from the server side.
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.
Demo.htm foreground display.
server.asp background Read data
<% @Language = "JavaScript"%>
<%
function Opendb (sdbname)
{
/*
*---------------opendb (sdbname)-----------------
* OPENDB (Sdbname)
* Function: Open database Sdbname, return conn object.
* Parameters: Sdbname, String, database name.
* Example: var conn = opendb ("Database.mdb");
* AUTHOR:WANGHR100 (Grey bean baby. NET)
* Update:2004-5-12 8:18
*---------------opendb (sdbname)-----------------
*/
var connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" Data source= "+server.mappath (sdbname);
var conn = Server.CreateObject ("ADODB.") Connection ");
Conn. Open (CONNSTR);
Return conn;
}
var sresult = new Array ();
var oconn = 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-1 12:22
var sql = "Select num1,num2 from Nums order by id";
var rs = oconn.execute (SQL);
while (!rs. EOF)
{
A record is separated by "###". Each column of data is separated by "@@@". This is in the case of only two columns of data.
Sresult[sresult.length] = rs ("Num1"). Value + "@@@" + RS ("num2"). Value
Rs. MoveNext ();
}
Escape solved the XMLHTTP. Chinese to deal with the problem.
Response.Write (Escape (Sresult.join ("###"));
%>
Database Data.mdb
Table Nums
ID, automatic numbering
NUM1, text
num2, text
Test data
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