【发布时间】:2015-05-08 08:31:31
【问题描述】:
我有以下 ajax 调用:
$.ajax({
type: "POST",
url: urlToGetRules,
data: { ruleName: ruleName},
})
.success(function (data) {
document.location.href = "/StudentRules/GetAllStudentRules?productId=test";
})
.fail(function (xhr) {
alert("Something went wrong!!!")
console.log(xhr.responseText);
});
在我的控制器中,我正在 DocDb 中创建一个文档,如下所示:
[HttpPost]
public ActionResult UpsertDoc(string ruleName)
{
StudentRule studentRule = new StudentRule() { Id = Guid.NewGuid().ToString(), StudentId = "test", Name = ruleName, RuleType = "Allow all updates", StartDate = DateTime.UtcNow.ToString() };
_updateScheduleRulesManager.UpsertScheduleRule(studentRule);
return Json(new { success = true });
}
这个想法是在用户在“添加规则”页面中创建新规则后返回到我列出所有规则的页面。
上面的代码执行得很好,我可以在 Docdb 中看到预期的文档,但是在开发者工具中这个调用的状态显示为 'pending'!!! Success 中的代码永远不会执行。
有人可以在这里指导我吗?
提前致谢。
【问题讨论】:
-
调试控制器方法时会发生什么?它有没有打到
return行? -
它确实击中了控制器。
-
不管是否命中控制器,能不能在
return这一行下断点,是否命中?可能是挂起的更新语句。 -
如果我删除你的数据库更新代码并且只保留 return Json(new { success = true });那么您的代码工作正常,所以看起来您的更新代码中有一些错误。
-
@mattytommo 你又来了? :)
标签: jquery asp.net ajax asp.net-mvc asp.net-mvc-4