问题描述
<body><divclass="login"><divclass="user">用户名:<inputtype="text"name="userName"id="userName"></div><divclass="user">密 码:<inputtype="password"name="userPass"id="userPass"></div><divclass="user"><inputtype="button"name="submit"id="submit"value="登 录"class="subns"onclick="Check()"></div></div></body></html><scripttype="text/javascript">functionGE(a){returndocument.getElementById(a);}functionCheck(){varusername=GE("userName"),userpass=GE("userPass");if(username.value==""){alert("用户名不能为空");username.focus();return;}if(userpass.value==""){alert("密码不能为空");userpass.focus();return;}varX=newActiveXObject("Msxml2.XMLHTTP");if(X){GE("submit").disabled=true;X.onreadystatechange=function(){if(X.readyState==4){if(X.status==200){eval(X.responseText)}else{alert(X.statusText);return;}}else{alert("正在提交数据");return;}};X.open('POST','logincs.asp',true);X.setRequestHeader("Content-Type","application/x-www-form-urlencoded");varSendData='userName='+username.value+'&userPass='+userpass.valueX.send(SendData);}else{alert("你的浏览器不支持XMLHttpRequest");return;}}</script><!--#includefile="include/Conection.asp"--><!--#includefile="include/Encryption.asp"--><%dimsql,rsdimusername,password,CheckCode,hiddenusername=replace(trim(request("username")),"'","")password=replace(trim(Request("password")),"'","")password=md5(password)setrs=server.createobject("adodb.recordset")sql="select*fromadminwherepassword='"&password&"'andusername='"&username&"'"rs.opensql,conn,1,3ifrs.bofandrs.eofthenresponse.write"<scriptlanguage=javascript>alert('用户不存在');history.go(-1);</script>"response.endelseifpassword<>rs("password")thenresponse.write"<scriptlanguage=javascript>alert('密码错误');history.go(-1);</script>"response.endelsers("LastLoginIP")=Request.ServerVariables("REMOTE_ADDR")rs("LastLoginTime")=now()rs("LoginTimes")=rs("LoginTimes")+1rs.updatesession("adminname")=rs("usname")session("admincomp")=rs("comany")session("adminsection")=rs("section")session("adminpost")=rs("post")rs.closesetrs=nothingcallCloseConn()Response.Redirect"adminmdex.asp"endifrs.closesetrs=nothingendifcallCloseConn()%>
解决方案
本帖最后由 showbo 于 2011-10-30 11:45:03 编辑
解决方案二:
第一,ajajx状态每次变换都会提示你那个信息,你代码的问题第二,你用eval执行代码不需要输出script标签了,这样会导致eval出错ifrs.bofandrs.eofthen'response.write"<scriptlanguage=javascript>alert('用户不存在');history.go(-1);</script>"response.write"alert('用户不存在');history.go(-1);"response.endelseifpassword<>rs("password")then'response.write"<scriptlanguage=javascript>alert('密码错误');history.go(-1);</script>"response.write"alert('密码错误');history.go(-1);"response.end
而且你不要在服务器端进行跳转,而是ajax根据动态页返回的值进行跳转参考
解决方案三:
--看的好晕..这是vb.net?