jquery 无刷新登录—.net后台交互的问题

碰到一个问题弄了很长时间,后台response.write("success"),jquery的ajax可以接收到,但是因为resoponse.write()生成的是html形式的, 如果用OK来判断登录的密码和用户名是否正确,就会有问题了。所以的用response.wirte("<div>success</div>");

贴出代码:前台js:

 

代码
 
   
$(function(){
$(
" #logonbutton " ).click(function(){
var username
= $( " #user_name " ).val();
var userpwd
= $( " #user_pass " ).val();
var usercode
= $( " #imgCode " ).val();
if (username == "" )
alert(
" 用户名不能为空! " )
if (userpwd == "" )
alert(
" 密码不能为空! " )
if (usercode == "" )
alert(
" 验证码不能为空! " )
$.ajax({
type:
' post ' ,
url:
' ajaxData.aspx ' ,
data:{
" name " :username, " pwd " :userpwd, " code " :usercode},
success:function(str)
{
$(
" #resultMessage " ).html(str);
var returntext
= $( " #resultMessage " ).text();
if (returntext.substring( 0 , 7 ) == ' success ' )
{
alert(
" 登录成功,按确定后跳转到首页! " );
location.href
= " index.aspx?userName= " + username + "" ;
}
else
{
if (returntext.substring( 0 , 6 ) == " 用户名不存在 " || returntext.substring( 0 , 8 ) == " 请输入有效用户名 " )
{
// 注意这里的substring(0,8)字符个数
alert( " 用户名不存在! " );
$(
" #user_name " ).focus();
}
if (returntext.substring( 0 , 4 ) == " 密码错误 " )
{
alert(
" 密码错误! " );
$(
" #user_pass " ).focus();
}
if (returntext.substring( 0 , 5 ) == " 验证码错误 " )
{
alert(
" 验证码错误! " );
$(
" #imgCode " ).focus();
}
return ;
}
}
});
});
});

 

后台:

代码
 
   
if ( ! string .IsNullOrEmpty(Request.Params[ " name " ]) && ! string .IsNullOrEmpty(Request.Params[ " name " ]) && ! string .IsNullOrEmpty(Request.Params[ " code " ]))
{
userName
= Request.Params[ " name " ].ToString().Trim();
userPass
= Request.Params[ " pwd " ].ToString().Trim();
imgCode
= Request.Params[ " code " ].ToString().Trim();
tuser
= UserDB.GetUserInfoByUID(userName);

string validateCode = "" ;
if (Session[ " num " ] != null )
{
validateCode
= Session[ " num " ].ToString(); // 获得验证码
}

if (tuser == null )
{
Response.Write(
" <div>请输入有效用户名</div> " );
}
else if ( ! tuser.FuserName.Equals(userName))
{
Response.Write(
" <div>用户名错误</div> " );
}
else if ( ! tuser.FpassWord.Equals(userPass))
{
Response.Write(
" <div>密码错误</div> " );
}
else if ( ! imgCode.Trim().ToLower().Equals(validateCode.ToLower()))
{
Response.Write(
" <div>验证码错误</div> " );
}
else if (tuser != null && tuser.FpassWord.Equals(userPass))
{
Session[
" user " ] = tuser.FuserName;
Response.Write(
" <div>success</div> " );
// Response.Write("<div class=\"act\">ok</div>");
// Response.End();
}

 

 

转载于:https://www.cnblogs.com/sheseido/archive/2010/11/12/1875915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值