ShuDudu's Home was started in 2011, but the web data is lost, so now begin again, I would like to make some friends, I hope you like ShuDudu's home.
Current position: ShuDudu > Life >

Use XMLHTTP to obtain data without refresh.

Thursday on January 1st, 1970Life

there are several ways to interact data between client and server.

1. Submit, by submitting to the server. Also known as "there is refresh".
2. Submit it to the server without refresh through XMLHTTP and return the data. Also known as "no refresh".
We can implement a lot of powerful applications with XMLHTTP. This article mainly introduces some simple applications of
.

attachment: because XMLHTTP is an object supported by IE5.0+. So you must have IE5.0+ to see the effect.

client.htm

 & lt;script language="JavaScript">Function GetResult (str){/**-GetResult (str)-* GetResult (str)* function: send a request through XMLHTTP and return the result.* parameters: str, string, sending condition.* instance: GetResult (document.all.userid.value)* author:wanghr100 (grey bean baby. Net)* update:2004-5-27 19:02*-GetResult (str)-,/Var oBao = new ActiveXObject (& quot;Microsoft.XMLHTTP")//Special characters: +,%, & ,=,? Wait for the transmission solution. The string is first encoded in escape.//Update:2004-6-1 12:22OBao.open (& quot;POST","server.asp?userid="+escape (str), false)OBao.send ()//the server-side processing returns a string encoded by escape.Document.all.username.value=unescape (oBao.responseText)}& lt;/script>& lt;input type="button" onclick="GetResult (document.all.userid.value) & quot; value="Get"> 

server.asp server-side processing.

 & lt;% @ Language="JavaScript"% & gt& lt;%Function OpenDB (sdbname){/**-OpenDB (sdbname)-* OpenDB (sdbname)* function: open the database sdbname and return the conn object.* parameters: sdbname, string, database name.* example: var conn = OpenDB (& quot;database.mdb")* author:wanghr100 (grey bean baby. Net)* update:2004-5-12 8:18*-OpenDB (sdbname)-,/Var connstr = & quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath (sdbname)Var conn = Server.CreateObject (& quot;ADODB.Connection")Conn.Open (connstr)Return conn}Var sResult = & quot;"Var oConn = OpenDB (& quot;data.mdb")//Special characters: +,%, & ,=,? Wait for the transmission solution. Client characters are encoded by escape//so the server has to be decoded by unescape first.//Update:2004-6-1 12:22Var userid = unescape (Request & quot;userid")Var sql = & quot;select username from users where userid='"+userid+"'"Var rs = oConn.Execute (sql)If (! rs.EOF){SResult = rs (& quot;username") .Value}Else{//add fault tolerance. 2004-5-30 10:15SResult = & quot;Sorry, not found. & quot}//escape solved XMLHTTP. The problem of Chinese processing.Response.Write (escape (sResult))% & gt

Database Design data.mdb
Table users.
Field
id automatic numbering
userid text
username text

Table: users data:
id userid username
1 wanghr100 Gray Bean Baby. Net

--
from: Gray Bean Baby. Net

Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/Use-XMLHTTP-to-obtain-data-without-refresh.htm