无刷新查询数据
Client.Htm
----------------------------------
<script language="JavaScript">
function GetResult(str)
{
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("POST","Client.asp?userid="+escape(str),false);
http.send();
document.all.username.value=unescape(http.responseText); // unescape 解码
document.all.MyDiv.innerText = unescape(http.responseText);
}
</script>
<input type="button" onclick="GetResult(document.all.userid.value)" value="Get"><br>
测试ID:<input type="text" name="userid"><br>
返回:<input type="text" name="username">
<div id="MyDiv"></div>
------------------------------------
Client.Asp
------------------------------------
<% @Language="JavaScript" %>
<%
var sResult = "";
var ConnStr = "Driver={Sql Server};Server=localhost;DataBase=Num;Uid=iNum;Pwd=iNum;";
var Conn = Server.CreateObject("Adodb.Connection");
Conn.ConnectionString = ConnStr;
Conn.Open();
var userid = unescape(Request("userid"));
var sql = "select * from Num where id=\'"+userid+"\'";
var rs = Conn.Execute(sql);
if(!rs.EOF)
{
sResult = rs("Num").Value;
}
else
{
sResult = "Null"
}
Response.Write(escape(sResult)); //字符需要 escape 编码
%>
-----------------------------------------