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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With