开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜