【发布时间】:2015-10-03 17:27:35
【问题描述】:
我正在尝试对服务器进行 ajax 回调以将新数据保存到数据库中: 这是我的代码:
$.ajax({
type: 'POST',
url: '@Url.Action("SaveNewApplication")',
contentType: 'application/json; charset=utf-8',
data: {
appName: newAppName,
appDesc: newAppDesc,
expire: newDaysToExpire,
displayNote: newDspNote,
adminRole: newAdminRole,
defualtRole: newDefaultRole,
active: newIsActive
},
dataType: '',
success: function () {
alert("new data has been saved");
},
error: function () {
alert("Error happened whiles saving the new application data");
}
});
我在“SaveNewApplication”函数处设置了一个断点,但断点从未命中! 这里是“SaveNewApplication”函数:
[HttpPost]
[OutputCache(Duration = 0)]
public void SaveNewApplication(string appName, string appDesc, int expire, string displayNote, string adminRole,
string defualtRole, bool active)
{
}
ajax调用中的成功函数永远不会执行
【问题讨论】:
-
您的 contentType 错误,或者您的数据以错误的格式发送。 jQuery 不会自动将您的对象转换为 json,如果您想使用
JSON.stringify(thedata)发布 JSON,则必须自己执行此操作 -
你检查过firebug中的任何错误吗?
标签: javascript jquery asp.net ajax asp.net-mvc-3