xml| Data | refresh | no refresh
There are several ways to interact between client and server-side data.
1. Submit, via <form></form> submit to server side. It is also called "Refresh".
2. Submit to server by XMLHTTP without refreshing, and return data. Also known as "no Refresh" bar.
Using XMLHTTP we can achieve a lot of very powerful applications. This article mainly introduces one of its
A few simple applications.
Attached: Because XMLHTTP is an object supported by ie5.0+. So you have to have ie5.0+ to see the effect.
Client.htm
<script "JavaScript"
function language= (str)
{
/*
*---------------getresult (str)-----------------
* GetResult (str)
* function: Sends a request through XMLHTTP to return the result.
* parameter: str, string, send condition.
* instance: GetResult (Document.all.userid.value);
* author:wanghr100 (Gray bean Baby. net)
* update:2004-5-27 19:02
*---------------getresult (str)- ----------------
*/
var obao = new ActiveXObject ("Microsoft.XMLHTTP");
//special characters: +,%,&,=, etc. transmission solutions. The string is encoded first with escape.
//update:2004-6-1 12:22
Obao.open ("POST", "server.asp?userid=" +escape (str), false);
Obao.send ();
Server-side processing returns a string that is encoded by escape.
Document.all.username.value=unescape (Obao.responsetext)
}
</script>
<input type= "button" value= "Get" ><br>
Userid:<input type= "text" name= "userid" ><br>
Username:<input type= "text" name= "username" >
Server.asp server-side processing.
<% @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 = "";
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 UserID = unescape (Request ("userid"));
var sql = "Select username from users where userid= '" +userid+ "";
var rs = oconn.execute (SQL);
if (!rs. EOF)
{
Sresult = RS ("username"). Value;
}
Else
{
//Add fault tolerance. 2004-5-30 10:15
Sresult = "Sorry, not found ..."
}
//escape solved the XMLHTTP. Chinese to deal with the problem.
Response.Write (Escape (Sresult));
%>
Database Design Data.mdb
Table users.
Field
ID Auto Number
UserID text
Username text
table: Users data:
ID userid Username
1 wanghr100 baby grey peas. Net