为什么不现代浏览器都支持PUT和DELETE方法的形式? [英] Why don't the modern browsers support PUT and DELETE form methods?

查看:2877
本文介绍了为什么不现代浏览器都支持PUT和DELETE方法的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成建设一个RESTful API,用于我的最新的应用程序之一。我还建立了一个简单的管理界面脚手架类,将枚举资源并建立简单的表格和表格编辑,创建,删除等。

I just finished building a RESTful API for one of my latest apps. I also built a simple admin interface scaffolding class that will enumerate resources and build simple forms and tables to edit, create, delete etc.

有关更新和删除资源类输出形式PUT方法和DELETE,pretty简单:

For updating and deleting resources, the class outputs a form with methods of PUT and DELETE, pretty simple:

<form action="/posts/xxxxxxx" method="DELETE">
<input type="submit" value="Delete" />
</form>

<form action="/posts/xxxxxxx" method="PUT">
<input type="text" name="username" value="nikcub" />
<input type="text" name="fullname" value="Nik Cubrilovic" />
<input type="text" name="email" value="nikcub@email.com" />
<input type="submit" value="Update" />
</form>

很简单。如果检测到的Javascript,那么它会拦截的形式和使用XMLHTT prequest提交回。 JavaScript的支持其他HTTP方法,但你为什么不现代浏览器支持PUT和DELETE方法?它最终发送一个GET。

Very simple. If Javascript is detected, then it will intercept the form and use an XMLHTTPRequest to submit back. The Javascript supports the other HTTP methods, but why don't modern browsers support the PUT and DELETE methods? It ends up sending a GET.

我preFER,当该应用摆好回退到该同样的方法被使用,而不必使用隐藏字段和在类的逻辑,或者更糟的是,把方法中的标准的HTML URI并允许开始工作。

I would prefer that when the app gracefully falls back to standard HTML that the same methods are used, instead of having to use hidden fields and the logic for that in the class, or worse, putting the method in the URI and allowing GET to work.

我想不出任何理由的浏览器不支持其他的HTTP方法,因为开发人员就在它的工作无论如何因黑客行为GET或POST使用

I can't think of any reasons why browsers wouldn't support the other HTTP methods, since developers are just working around it anyway by hacking GET or using POST.

我寻找一个答案,并且能找到它指定为的XHTML 2.0规范的一部分。没有它提到了HTML5规范

I searched for an answer, and was able to find it specified as part of the XHTML 2.0 spec. There is no mention of it in the HTML5 spec.

因为它不是在兼容HTML5的浏览器所支持的任何原因?我在哪里可以张贴的要求打开此备份并把它在浏览器中实现?

Any reason for it not being supported in the 'HTML5 compliant' browsers? Where can I post a request to open this back up and get it implemented in browsers?

推荐答案

一些Web框架(如Ruby on Rails的)解决了通过在一个隐藏 _method 参数

Some web frameworks (e.g. Ruby on Rails) get around that by including a hidden _method parameter in the form with the value of the "actual" method, e.g.:

<form action="/posts/xxxxx" method="POST">
    <input type="hidden" name="_method" value="DELETE">
    <input type="submit" value="delete">
</form>

然后该框架上改写处理之前在服务器端请求使用 _method 参数作为HTTP方法的价值。

The framework then rewrites the request on the server side before processing to use the value of the _method parameter as the HTTP method.

不知道这是否可以帮助你。

Don't know if this helps you.

这篇关于为什么不现代浏览器都支持PUT和DELETE方法的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆