ServiceStack Backbone.Todos 删除 405 不允许 [英] ServiceStack Backbone.Todos Delete 405 not allowed

查看:16
本文介绍了ServiceStack Backbone.Todos 删除 405 不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到当单击 Backbone.Todos 示例清除 x 已完成的项目"时,我得到一个 DELETE 405 不允许...

I realized when click Backbone.Todos example "Clear x completed items" I get a DELETE 405 not allowed...

我从之前的帮助和文档中了解到,如果我想启用 DELETE PUT PATCH ...我需要设置

I understand from the pervious helps and docs that if I want to enable DELETE PUT PATCH ... I need to set

X-http-method-override : DELETE

如果它是表单或在 jquery 中.

if it was a form or in jquery.

但我不确定在 Backbone.Todos 示例中这是如何完成的,因为我是 Backbone.js 的新手.

But I am not sure how this is done in the Backbone.Todos example as I am new to backbone.js.

你能指出如何修复 DELETE 405 吗?谢谢.

Could you please point out how to fix the DELETE 405 ? Thank you.

编辑 ---------------------------------------

EDIT ---------------------------------------

我可以随时将路线更改为...

I can always change routes to ...

[Route("/todos/add")] //C - post
[Route("/todos/{id}")] //R - get
[Route("/todos/{id}/edit")] //U - post
[Route("/todos/{id}/delete")] //D - post

所以,只有 Post 和 Get 就足以完成这项工作.但与以下相比,它看起来不是很 Restful:

So, only Post and Get are enough to do the job. But it doesn't look very Restful compare to:

[Route("/todos/{id}", "Delete")] //D - delete

是吗?

推荐答案

Backbone.js 对此有特殊支持,您可以通过以下方式启用:

Backbone.js has special support for this, which you can enable with:

Backbone.emulateHTTP = true

来自他们的网站:

如果您想使用不支持的旧式 Web 服务器Backbones 默认的 REST/HTTP 方式,你可以选择开启Backbone.emulateHTTP.设置此选项将伪造 PUT 和 DELETE使用 HTTP POST 请求,设置 X-HTTP-Method-Override 标头用真正的方法.如果 emulateJSON 也打开,真正的方法将作为额外的 _method 参数传递.

If you want to work with a legacy web server that doesn't support Backbones's default REST/HTTP approach, you may choose to turn on Backbone.emulateHTTP. Setting this option will fake PUT and DELETE requests with a HTTP POST, setting the X-HTTP-Method-Override header with the true method. If emulateJSON is also on, the true method will be passed as an additional _method parameter.

Backbone.emulateHTTP = true;

model.save();  // POST to "/collection/id", with "_method=PUT" + header.

405 响应可能是在 IIS 中运行其他东西(如 WebDav)的结果,这些东西会在请求到达 ServiceStack 之前劫持并拒绝该请求.否则,如果它被客户端拒绝,您可能需要启用 CORS 以允许额外的 HTTP要发送的动词.

The 405 response may be the result of having something else running in IIS like WebDav that will hijack the and reject the request before it reaches ServiceStack. Otherwise if it's being rejected on the client you may want to enable CORS to allow additional HTTP Verbs to be sent.

这篇关于ServiceStack Backbone.Todos 删除 405 不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆