0

我有一个使用 OData 和 Knockout Js 的应用程序。在我的应用程序中,我使用 POST、GET 和 DELETE HTTP 动词,当我托管我的应用程序时,GET 和 POST 不会引发任何错误,但 DELETE 会引发错误,不知道如何修复它。

以下是我使用 DELETE 的地方

self.remove = function (canadiancrude) {

        var conf = confirm("Are you sure you want to delete this record?");
        if (conf == true) {
            $.ajax({
                url: '/odata/Canadiancrudes(' + canadiancrude.Id + ')',
                type: 'DELETE',
                contentType: 'application/json',
                dataType: 'json'
            });
        }
    }

错误是

405 - HTTP verb used to access this page is not allowed.
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

"NetworkError: 405 Method Not Allowed

我如何解决它

4

2 回答 2

2

尝试修改您的请求:

$.ajax({
    url: '/odata/Canadiancrudes(' + canadiancrude.Id + ')',
    type: 'DELETE',
    dataType: 'json',
    headers: { 
        "Content-Type": "application/json",
        "X-HTTP-Method-Override": "DELETE" }
});

此外,如果您使用 IIS,您可以执行以下步骤:
1) 在控制面板中,单击程序和功能,然后单击打开或关闭 Windows 功能。
2) 展开 Internet Information Services,然后是 World Wide Web Services,然后是 Common HTTP Features。
3)取消选择WebDAV 发布,然后单击确定。

于 2014-02-20T22:48:49.040 回答
2

甚至将以下几行添加到我的 web.config 对我有帮助

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule"/>
    </modules>
于 2014-02-21T17:12:00.160 回答