不允许使用 IE 11 $.ajax PUT 方法

Using IE 11 $.ajax PUT method not allowed

在我的编辑页面上,我使用的是 api 控制器。

这是我的 $.ajax:

var settings = {};
settings.baseUri = '@Request.ApplicationPath';
var infoGetUrl = "";
if (settings.baseUri === "/ServerProjectName") {
    infoGetUrl = settings.baseUri + "/api/controllerName/";
} else {
    infoGetUrl = settings.baseUri + "api/controllerName/";
}

$("#Edit-Btn").on("click",
    function(e) {
        $("form").validate({
            submitHandler: function() {
                e.preventDefault();

                $.ajax({
                    method: "PUT",
                    url: infoGetUrl,
                    data: $("form").serialize(),
                    success: function(data) {
                        toastr.options = {
                            onHidden: function() {
                                window.location.href = newUrl;
                            },
                            timeOut: 3000
                        }
                        toastr.success("Successfully edited.");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        var status = capitalizeFirstLetter(textStatus);

                        toastr.error(status + " - " + jqXHR.responseText);
                    }
                });
            }
        });
    });

此方法下方是 'DELETE' 的另一个 ajax 函数,它运行良好。只有 PUT 方法给我这个错误。

当我提交时,我收到一条错误消息:

The requested resource does not support http method 'PUT'

我看过this但不太明白。我用的是IE 11,所以我觉得应该支持。

非常感谢任何想法或帮助。

您收到此消息的原因是您尝试使用的 API 不支持 HTTP PUT 方法。

通常,如果您使用的是 Web api 2.0,则 Web 方法的属性如果支持 PUT,则具有 [HttpPut]。还有其他方法可以标记 API 以支持 Put,但通常不使用。

确认您的 API 是问题的最简单方法是使用 Postman 尝试使用 API,这样可以消除您的 javascript 可能遇到的任何问题。