這是JavaScript的樣子Ajax調用示值誤差着調試
<script type="text/javascript">
$(document).ready(function() {
$('#loginButton').click(function() {
//this.disabled = true;
debugger;
var data = {
"userid": $("#username").val(),
"password": $("#password").val()
};
$.ajax({
url: "/Account/LoginPost",
type: "POST",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json",
success: function (response) {
if (response.Success) {
$.get("@Url.Action("Search", "Home")", function (data) {
$('.container').html(data);
});
}
else
window.location.href = "@Url.Action("Index", "Home")";
},
error: function() {
alert('Login Fail!!!');
}
});
});
});
我收到警報(「登錄失敗」)還沒有調試得到擊中。 我使用jQuery 1.9.1,並已列入unobstrusive
我的控制器是這樣的,你可以我傳遞 當頁面字符串值不反對值到控制器,以便字符串化在這裏
[HttpPost]
public JsonResult LoginPost(string userid, string password)
{
using (someentities wk = new someentities())
{
var LoginUser = wk.tblUsers.Where(a => a.Username.Equals(userid)&&a.Password.Equals(password)).FirstOrDefault();
if (LoginUser != null)
{
FormsAuthentication.SetAuthCookie(userid,false);
Session["Username"] = LoginUser.Username;
Session["Password"] = LoginUser.Password;
Session["Name"] = LoginUser.Name;
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}
else
{
TempData["Login"] = "Please Enter Correct Login Details";
return Json(new { Success = false }, JsonRequestBehavior.AllowGet);
}
}
// If we got this far, something failed, redisplay form
}
合理裝載這些誤差如圖所示
$(..) live is not a valid function in (anonymous function) @ jquery.unobtrusive-ajax.js:115 (anonymous function) @ jquery.unobtrusive-ajax.js:163
那麼你在網絡面板上看到了什麼?在$'.ajax'中設置' – epascarello
',當服務器返回'error'時觸發ERROR,所以你會想嘗試'error:function(obj){console.log(obj);'看看服務器有什麼錯誤正在返回。 – imvain2
@epascarello說,如果不知道它是服務器端錯誤還是客戶端錯誤,我們將無法給予你很多幫助,儘管它已經達到了錯誤回調而不是成功,它似乎更可能是服務器端錯誤。 –