js代码:
function LoginSuccess(){
    $.ajax({
            type:"POST",
            url:"checkLogin.aspx",
            
            data:{userName:$("#txtUser").val(),userPwd:$("#txtPassword").val()},
            beforeSend:function(){$("#msg").html("logining");},             
            success:function(msg){           
            //这里msg经过测试,返回的确实是Login is false,但是始终无法执行if以下的语句
            if(msg=="Login is false")
            {
                $("#msg").html(msg);
            }
                   
            }    
                               
         });
.cs后台代码:            string retVal = "";
            string userName = Request["userName"];
            string userPwd = Request["userPwd"];
            if (userName == "test" && userPwd == "test")
            {
                retVal = "Login is Success";
                
            }
            else
            {
                retVal = "Login is false";
            }
            Response.Write(retVal);
            Response.End();问题描述:
本人菜鸟,反复折腾无用.但经过测试,js里面,返回值是对的,但是不能执行success下的if语句.求解!

解决方案 »

  1.   

    返回0或者1试试,有时候,js里面的判断比较会抽筋,尤其是这种情况:
    if(!flag){}明明flag是false,也不进if块。
      

  2.   

    .cs后台代码:  string retVal = "";
      string userName = Request["userName"];
      string userPwd = Request["userPwd"];
      if (userName == "test" && userPwd == "test")
      {
      retVal = "Login is Success";
        
      }
      else
      {
      retVal = "Login is false";
      }
      Response.Write(retVal);
      Response.End();把这些东西放到ashx页面中试试
      

  3.   

    if(msg === "Login is false")试试
      

  4.   

     public void ProcessRequest(HttpContext context)
            {
                string retVal = "";
                string userName = context.Request["userName"];
                string userPwd = context.Request["userPwd"];
                if (userName == "test" && userPwd == "test")
                {
                    retVal = "Login is Success";            }
                else
                {
                    retVal = "Login is false";
                }
                context.Response.Write(retVal);
            }
      

  5.   

    checkLogin.aspx的页面是干净的不?
      

  6.   

    success:function(msg){   
      //这里msg经过测试,返回的确实是Login is false,但是始终无法执行if以下的语句
       alert(msg);//这里测试一下返回的是什么?
      if(msg=="Login is false")
      {
      $("#msg").html(msg);
      }