Jquery Ajax调用永远不会返回

Jquery Ajax调用永远不会返回,jquery,asp.net,ajax,asp.net-mvc,asp.net-mvc-4,Jquery,Asp.net,Ajax,Asp.net Mvc,Asp.net Mvc 4,我有以下ajax调用: $.ajax({ type: "POST", url: urlToGetRules, data: { ruleName: ruleName}, }) .success(function (data) { document.location.href = "/StudentRules/GetAllStudentRules?pro

我有以下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中看到预期的文档,但是在开发人员工具中调用的状态显示为“挂起”!!! Success中的代码永远不会执行

有人能带我到这里吗


提前感谢。

我认为有一个问题,您在请求中没有传递
productid
,请在ajax调用中检查此项

data: { ruleName: ruleName},
其中没有productid,其中方法productid是参数

public ActionResult UpsertDoc(string ruleName, string productId)
您的数据元素应该是并添加数据类型

data: { ruleName: 'name of rule', productId: 'productid' }, 
datatype : 'json'

没有
.success
处理程序

弃用通知:jqXHR.success()、jqXHR.error()和 jqXHR.complete()回调从jQuery 1.8开始就不推荐使用。准备 要最终删除它们,请使用jqXHR.done()、jqXHR.fail(), 而jqXHR.always()则相反

您需要使用“完成”:

  $.ajax({
        type: "POST",
        url: '@Url.Action("UpsertDoc")',
        data: { ruleName: 'test'},
        }).done(function (data) {
            document.location.href = "/StudentRules/GetAllStudentRules?productId=test";            
        }).fail(function (xhr) {
        alert("Something went wrong!!!")
        console.log(xhr.responseText);
        });
同时删除
.done
.fail
之前的间距

屏幕截图


虽然你是对的,但这对他遇到的问题没有任何影响。@mattytommo-如果是这样,则需要调试代码。.还需要检查url是否正确,degguer点击方法调用,即我说过的操作方法,它确实命中了断点,并且databae操作成功,但调用永远不会返回到成功状态。调试控制器方法时会发生什么?它是否击中了
返回
行?它确实击中了控制器。无论它是否击中控制器,您能否在
返回
行上设置断点,它击中了吗?可能是update语句挂起了;然后,您的代码工作正常,所以更新代码中似乎有一些错误。@mattytom是否再次在此处登录?:)我认为这是OP代码中的一些狡猾的括号(认为这是一个粘贴错误),没有意识到他在使用这种语法!好地方;)那怎么是个“好地方”?除了个人审美之外,它有什么实际的区别吗?@ToddGrigsby jQuery版本没有
success
方法,因此它永远不会起作用。弃用通知:从jQuery 3.0开始,jqXHR.success()、jqXHR.error()和jqXHR.complete()回调将被删除。您可以改用jqXHR.done()、jqXHR.fail()和jqXHR.always()。