2014-10-30 63 views
0

我有一個表單,用戶進行登陸新頁面或阿勒特OK $ NOK登錄表單在asp.net的MVC的jQuery

<form role="form" id="loginforms"> 
<input type="text" class="search-form" autocomplete="off" id="username"> 
<i class="fa fa-user"></i> 
<input type="password" class="search-form" autocomplete="off" id="password"> 
<i class="fa fa-lock"></i> 
<input type="submit" value="ورود" class="btn btn-success" id="login"> 
</form> 

和我的控制器來獲得數據:

[HttpPost] 
    public JsonResult GetUserNames(string uname, string pass) 
    { 
     bool status; 
     var persons = this.prf_personRepository.Query.Where(c => c.UserName == uname && c.Password == pass) 
      .Select(c => new { c.UserName,c.Password}).ToList(); 
     if (persons != null) 
     { 
      status = true; 
     } 
     else 
     { 
      status = false; 
     } 
     return Json(status, JsonRequestBehavior.AllowGet); 
    } 

和jQuery代碼:

<script> 
    $(document).ready(function() { 
     $("#login").click(function() { 
      $("#message").html("Logging in..."); 
      var data = { "uname": $("#username").val(), 
      "pass": $("#password").val() 
      }; 
      var islogin = null; 
      $.ajax({ 
      url: "/register/GetUserNames", 
      type: "POST", 
      data: JSON.stringify(data), 
      dataType: "json", 
      contentType: "application/json", 
      success: alert("ok"), 
      Error: alert("not") 
     }); 
     }); 
    }); 
</script> 

當運行項目控制器設置狀態=真實的,但在劇本的成功是空

+0

你所說的「控制器設置的成功意味着=真正」? – Groyoh 2014-10-30 12:52:42

+0

我的意思是status = true – behzad 2014-11-01 06:20:36

回答

0

更改以下行

 success: alert("ok"), 
     Error: alert("not") 

 success: function(result){alert(result);}, 
     error: function(){alert("Error!")} 

我會建議去通過jQuery的文檔阿賈克斯
http://api.jquery.com/?s=ajax
http://learn.jquery.com/ajax/

+0

什麼是正確的結果類型的GetUserNames函數的jQuery工作正確? – behzad 2014-11-01 06:25:35

+1

JsonResult是正確的返回類型 – 2014-11-01 13:57:55