我有mvc 4控制器方法通過使用AJAX方法獲取一些數據。不幸的是它不工作。我在成功和錯誤領域做了一些事情。我需要得到這個代碼中的錯誤。在MVC控制器的Ajax調用中不顯示警報
的Ajax方法:
$(function() {
$('#btnSave').on('click', function (event) {
event.preventDefault();
debugger;
var country = $('#cnname').val();
var customerID = $('#CustomerId').val();
if (country == "United Kingdom") {
if (800 <= $('#SrcAmt').val() < 2000) {
$.ajax({
type: 'GET',
url: '/CustomerIdentity/IdentityList',
data: { 'customerId': customerId },
success: function (data) {
alert('ok');
},
error: function (event) {
alert('fail');
}
});
}
}
});
});
MVC控制器:
public JsonResult IdentityList(int customerId)
{
var customeridentity = db.CustomerIdentity.Include(c => c.Customer).Include(c => c.CountryIssued)
.Where(item => item.CustomerId == customerId);
if (customeridentity.Count() > 0)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
else
{
return Json(false, JsonRequestBehavior.AllowGet);
}
}
檢查什麼樣的錯誤你是在控制檯 – Rex
它沒有表現出..後法命中})獲得;在AJAX方法如何跟蹤的成功和錯誤 – user2710638