这是一个传统的异步登陆,利用Ajax实现的,主要代码如下:
客户端代码:
var http;
function Button1_onclick() {
if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
}
else {
alert("初始化失败!");
}
}
var sname = form1.Text1.value; //用户名
var spwd = form1.TextBox2.value; //密码
var url = "hide.aspx?name=" + sname + "&pwd=" + spwd + ""; //执行页,以及传参
url=encodeURI(url); //对url进行编码
http.onreadystatechange = Fun;
http.open("Get", url);
http.send(null);
}
function Fun() {
if (http.readyState == 4) {
var r = http.responseText;
alert(r);
}
}
服务器:(这些放在Form Loading事件中)
string sname = Request .QueryString ["name"];
string spwd = Request .QueryString ["pwd"];
string r = Isexist(sname, spwd); //用户名、密码验证的方法调用
Response.Clear();
Response.Write(r);
Response.End();