Automatically update data in real time with XMLHTTP without refreshing.

Source: Internet
Author: User
Tags sql net return string split first row client
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.











num1 num2



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



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.