【发布时间】:2014-03-21 19:55:29
【问题描述】:
我有一个使用 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
如何解决
【问题讨论】:
-
这个方法有没有[Authorize]属性?
-
是的,控制器方法具有整个页面的 [Authorize] 属性,不仅用于此 DELETE,而且它们工作正常
-
可能是 CORS 问题...这篇 SO 文章有帮助吗? stackoverflow.com/questions/19675835/…
-
同样使用 Fiddler 来验证 DELETE 实际上是浏览器发送的动词。它还可能在响应中为您提供比浏览器报告的更多信息
标签: knockout.js odata httpverbs