[英]ASP.NET MVC 500 (Internal Server Error) with ajax post method
我是 asp.net mvc 的新手,我嘗試使用 ajax 創建發布數據,當開發運行良好時,但是當我嘗試在服務器中發布 web 時,發布數據時出現錯誤,錯誤如下POST https://example.com/login-testing 500 (Internal Server Error)
。 我試圖尋找許多例子,但都失敗了。
這是我的代碼,也許您可以在我的代碼中找到任何問題:
index.cshtml 中的 JS 腳本
function login() {
var email = $('#input-email').val();
var password = $('#input-password').val();
if (email && password) {
$.ajax({
url: '@Url.Action("LoginTesting", "Auth")',
type: 'POST',
data: JSON.stringify({
email: email,
password: password
}),
dataType: 'json',
contentType: 'application/json',
success: function (data){
console.log(data);
if (data == 1) {
window.location.href = '@Url.Action("Index", "Home")';
} else {
$('#login-warning').show();
}
},
error: function (data) {
$('#login-warning').show();
}
});
} else if (!email) {
$('#text-danger-email').show();
} else if (!password) {
$('#text-danger-password').show();
}
}
controller
[Route("login-testing")]
public JsonResult LoginTesting(LoginViewModel smodel)
{
var email = smodel.email;
var password = smodel.password;
DBHandle sdb = new DBHandle();
var account = sdb.GetLoginVerify(email);
if (account.password != null)
{
if (BCrypt.Net.BCrypt.Verify(password, account.password ))
{
var detail = sdb.GetUserDetail(account.id);
if (detail != null)
{
Session["is_login"] = true;
Session["id"] = detail.id;
Session["fullname"] = detail.fullname;
Session["id_levels"] = detail.id_levels;
Session["levels"] = detail.levels;
return Json(1);
}
else
{
return Json(2);
}
}
else
{
return Json(3);
}
}
else
{
return Json(4);
}
}
請任何人幫我解決這個問題。
謝謝。
內部服務器錯誤可能意味着您的 program.cs 文件有問題。它們的放置順序很重要,放置不當實際上可能會導致這些錯誤。
500 內部服務器也意味着,根據我的說法,您的代碼有問題 Go 到 Chrome 開發工具並單擊網絡選項卡,在該選項卡中單擊 XHR 選項卡
也可以Debug the Code,逐行單步執行代碼,檢查哪里出了問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.