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

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

问题描述

我意识到,当点击Backbone.Todos例如清除点¯x完成的项目我得到一个DELETE 405不准...

我从透水理解帮助和文档,如果我想启用DELETE PUT PATCH ......我需要设置

X-HTTP的方法,重写:删除

如果这是一个形式或jQuery中。

但我不知道这是如何在Backbone.Todos例子,因为我是新来的Backbone.js的完成。

能否请你指出如何解决DELETE 405?谢谢你。

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

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

  [路线(/待办事项/添加)] // C  - 交
[路线(/待办事项/(编号))] //的R - 获得
[路线(/待办事项/ {ID} /编辑)] //ü - 交
[路线(/待办事项/ {ID} /删除)] //ð - 交

因此​​,只有POST和GET都足以胜任。不过,这并不显得很宁静的比较:

  [路线(/待办事项/(编号),删除)] //ð - 删除

是吗?


解决方案

Backbone.js的对这个特殊的支持,您可以启用

  Backbone.emulateHTTP = TRUE

从他们的网站:

emulateHTTP Backbone.emulateHTTP = TRUE


  

如果你想使用不支持传统的Web服务器,
  骨干网的默认REST / HTTP方法,您可以选择开启
  Backbone.emulateHTTP。设置这个选项将假PUT和DELETE
  用HTTP POST请求,设置在X-HTTP-方法,覆盖头
  与真正的方法。如果emulateJSON也导通,真正方法将
  作为一个额外的_method参数传递。


  Backbone.emulateHTTP = TRUE;model.save(); // POST为/收集/ ID,用_method = PUT+头。

405响应可以是具有别的运行中的IIS像WebDAV的,将劫持和拒绝请求到达ServiceStack之前的结果。否则,如果它被客户拒绝上可能要使CORS ,以允许更多的HTTP要发送的动词。

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

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

if it was a form or in jquery.

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

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

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

Does it?

解决方案

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

Backbone.emulateHTTP = true

From their website:

emulateHTTP Backbone.emulateHTTP = true

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.

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天全站免登陆