开发者

Should I use POST or DELETE verb in jQuery.ajax() function

开发者 https://www.devze.com 2022-12-20 19:38 出处:网络
This is from jQuery API docs: typeString Default: \'GET\' The type of request to make (\"POST\" or \"GET\"), default is \"GET\". Note: Other HTTP request methods, such as PUT and DELETE, can also b

This is from jQuery API docs:

typeString Default: 'GET' The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

I am going to make AJAX delete links with jQuery. What I would like to know is specifics about browser support for DELETE and PUT. Which browsers support it? Is it safer that I just go with POST?

Given that I work in ASP.NET MVC I can decorate my controller actions with both DELETE and POST so both can be accepted开发者_如何学Python.


Go with POST. You don't have to worry about browser support and future maintainers of your code will understand whats going on just fine.


You could go with POST then set a form field named X-HTTP-Method-Override to DELETE.

See SO question #467535 for specific examples:

Is it possible to implement X-HTTP-Method-Override in ASP.NET MVC?


Extract from form value and send request, call Html.HttpMethodOverride(HttpVerbs.Delete) in form.


If all you're doing is deleting an item with a certain ID, GET should suit your purposes: http://www.diffen.com/difference/Get_vs_Post

Just make sure you handle a case where someone tries to delete something that's already deleted

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号