這段代碼ASPX工作,但是這個代碼在MVC項目不工作.. 錯誤後:POST http://localhost:1208/AWD/Login.asmx/logi 500(內部服務器錯誤)內部錯誤500在ASP.Net AJAX請求
var Email = $("#uwd").val();
var pwd = $("#pwd").val();
jQuery.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/AWD/Login.asmx/logi",
data: "{'username':'" + Email + "','password':'" + pwd + "'}",
dataType: "json",
success: function (response) {
var obj = response.d;
alert(obj);
if (obj == "01") {
alert("login ok");
}
else {
alert("login no");
}
},
error: function (result) {
alert("Error");
}
});
[WebMethod] public static string logi(string username,string password) { string result = null; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString); SqlCommand ilogin = new SqlCommand("select *from login where email='" + username + "' and password='" + password + "' ", con); SqlDataAdapter da = new SqlDataAdapter(ilogin); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { result = "ok"; return result; } else { result ="no"; return result; } }
500狀態碼意味着問題與您的代碼在ASPX文件中。另請注意,最好爲data參數提供一個實際對象,以便jQuery可以正確地爲您編碼這些值,而不是一起竊聽JSON字符串。 –
他們是不正確的'url'?請檢查可能是'/ login'然後'/ logi'' –