jQuery Ajax发布请求回调不起作用

时间:2020-09-01 08:36:42

标签: jquery .net json ajax

我正在尝试将数据发布到我的控制器,这是我的发布请求;

            $.ajax({
                url: "/Shipment/SaveTrackingNumber/",
                type: "POST",
                data: JSON.stringify(obj),
                dataType: "json",
                contentType : "application/json",
                success: function (result) {
                    console.log(result);
                    if (result.success == true) {
                        newNotify.SuccessNotify("Kaydetme İşlemi", "Kargo Kodu Kaydedildi!", Page.Time);
                        setTimeout(function () {
                            window.location = "/Order";
                        }, (Page.Time + 1000));
                    }
                    else {
                        newNotify.WarningNotify("Kaydetme İşlemi", "Hata Oluştu!", Page.Time + 1000);
                    }
                }

            })

当请求进入我的方法时,几行后给出405错误,我的控制器方法返回json数据,但成功回调不起作用。当我尝试调试javascript并逐步移动时,它可以工作。它很奇怪,我该如何解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:0)

405失败了,所以永远无法达到

成功:函数(结果){}

它将达到错误。

错误:函数(结果){}

如果您需要获得成功,则需要返回2 ** http代码

或者,您可以始终使用哪个文件,而不考虑http状态代码

.always(function(result) {
    alert( result );
  });
相关问题