织梦CMS - 轻松建站从此开始!

我的网站

当前位置: 首页 > www-SE94SE-com > Javascript/Ajax >

ajax实现登岸验证 ------------------------------------------------

时间:2012-11-27 01:01来源:网络整理 作者:管理员 点击:
ajax实现登陆验证 -------------------------------------------------------------------------------- js文件如下: -------------------------------------------------------------------------------- -----------------------------------------------

ajax实现登岸验证 -------------------------------------------------------------------------------- js文件如下: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- var xmlHttp; function IMG1_onclick() { CheckIsValid(); } function CheckIsValid() { CreatXmlHttpRequest(); var userName=document.getElementById(AdminText); var passWord=document.getElementById(AdminPasswordText); var url=CheckLogin.aspx?userName=+escape(userName.value)+passWord=+escape(passWord.value); xmlHttp.open(GET,isValid) { var messageArea=document.getElementById(showMessage); var fontColor; if(isValid ==True) { window.location.href=ManagerControl.aspx; } else { fontColor=red; imgUrl=images/404.jpg; messageArea.innerHTML=img src=+imgUrl+/+font color=+fontColor++message+/font; } } cs文件如下: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.Sql; using System.Data.SqlClient; public partial class CheckLogin : System.Web.UI.Page { protected void Page_Load(object sender。www-36ab-com

string passWord) { bool isPassed = true; if ((userName == ConfigurationManager.AppSettings[AdminName]) (passWord == ConfigurationManager.AppSettings[PassWord])) { isPassed = true; } else { isPassed = false; } return isPassed; } } HTML代码如下: %@ Page Language=C# AutoEventWireup=true CodeFile=Manager.aspx.cs Inherits=Manager % !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head runat=server meta http-equiv=content-type content=text/html; charset=GB2312 / title王子的宫殿 http://www.dwww.cn /title meta name=keywords content=http://dwww.cn / meta name=description content=dwww.cn / link rel=stylesheet type=text/css href=default.css / script language=javascript type=text/javascript src=js/main.js /script /head body div id=outer div id=upbg style=left: 0px; top: 0px/div div id=inner div id=header h1span王子/span宫殿sup1.0/sup/h1 h2by 薛晓龙/h2 /div div id=splash/div div id=menu ul li class=firsta href=Default.aspx主页/a/li lia href=#博客/a/li lia href=MyPhotos.html相册/a/li lia href=#留言/a/li lia href=Myinfo.aspx联系我/a/li lia href=Manager.aspx背景打点/a/li /ul div id=dateAugust 1,val); } } } function setMessage(message。

EventArgs e) { Response .ContentType=text/xml; bool passed = ValiLogin(Request[userName],密码错误或者打点员名称错误; if (passed) { message = 登岸乐成; } string textxml; textxml = response+passed+passed.ToString()+/passed+message+message+ /message+/response; Response.Write(textxml); } private bool ValiLogin(string userName,url, 2006/div /div div id=primarycontent style=left: 200px; top: 0px; width: 204px; margin-top:100px div id=hreaderimg src=images/logins.gif alt=登岸 //div div id=Login label for=userName用户名:/labelinput id=AdminText type=text /nbsp;br / label for=passWord nbsp; nbsp; 密码:/labelinput id=AdminPasswordText type=password / br / br / img id=loginIMG src=images/login.gif alt=登岸 style=float:right; cursor:pointer onclick=return IMG1_onclick()/ /div /div div id=shopPlace style=width:100%; height:200px; span id=showMessage style=text-align:center; margin-left:200px;/span /div /div /div /body /html ,true); xmlHttp.onreadystatechange=callback; xmlHttp.send(null); } function CreatXmlHttpRequest() { try { xmlHttp = new ActiveXObject(Msxml2.XMLHTTP); } catch (e) { try { xmlHttp = new ActiveXObject(Microsoft.XMLHTTP); } catch (e2) { xmlHttp = false; } } if (!xmlHttp typeof XMLHttpRequest != undefined) { xmlHttp = new XMLHttpRequest(); } } function callback() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var mes=xmlHttp.responseXML.getElementsByTagName(message)[0].firstChild.data; var val=xmlHttp.responseXML.getElementsByTagName(passed)[0].firstChild.data; setMessage(mes, Request[passWord]); string message = 堕落啦。

(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
用户名: 验证码: 点击我更换图片
栏目列表
推荐内容