Html 应该在表单中使用 PUT 和 DELETE 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5162960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Should PUT and DELETE be used in forms?
提问by Earlz
Assuming my web application has full support of PUT and DELETE on the server side, should I make use of them?
假设我的 Web 应用程序完全支持服务器端的 PUT 和 DELETE,我应该使用它们吗?
Basically my question is how many browsers support this:
基本上我的问题是有多少浏览器支持这个:
<form method="PUT">
or
或者
<form method="DELETE">
Is there any benefits to using these two HTTP Methods other than being REST-compliant? (assuming the replacement for these two methods is the commonly used POST)
除了符合 REST 标准之外,使用这两种 HTTP 方法还有什么好处吗?(假设这两种方法的替代是常用的POST)
回答by leebriggs
Your question involves two closely related but separate standards, HTTP and HTML. The PUT and DELETE methods are part of HTTP. In HTTP they have obvious use in RESTful interfaces, and other services which build on HTTP such as Webdav.
您的问题涉及两个密切相关但独立的标准,HTTP 和 HTML。PUT 和 DELETE 方法是 HTTP 的一部分。在 HTTP 中,它们明显用于 RESTful 接口和其他基于 HTTP 的服务,例如 Webdav。
HTML up to version 4 only defines the use of POST and GET for forms. HTML5 at this time appears as though it may support the further methods. [note, support is not included in the current w3 draft]
版本 4 之前的 HTML 仅定义了表单的 POST 和 GET 使用。此时的 HTML5 似乎可以支持更多的方法。[注意,当前 w3 草案中不包含支持]
Any current browser support (I'm not directly aware of any) will be very limited and only really useful as an experiment at the bleeding edge.
任何当前的浏览器支持(我不直接知道任何支持)都将非常有限,并且仅作为最前沿的实验才真正有用。
回答by BMiner
GET, POST, PUT and DELETE (there are others) are a part of the HTTP standard, but you are limited to GET and POST in HTML forms at this time.
GET、POST、PUT 和 DELETE(还有其他)是 HTTP 标准的一部分,但此时您仅限于 HTML 表单中的 GET 和 POST。
As Andrew mentioned, you can use PUT and DELETE in AJAX requests; however, this only works in some browsers (see http://api.jquery.com/jQuery.ajax/).
正如安德鲁提到的,你可以在 AJAX 请求中使用 PUT 和 DELETE;但是,这只适用于某些浏览器(请参阅http://api.jquery.com/jQuery.ajax/)。