在 关于 REST 的维基文章表示如果您使用 example/resources DELETE,则表示您正在删除整个收藏.
In wiki article for REST it is indicated that if you use example/resources DELETE, that means you are deleting the entire collection.
如果您使用 example/resources/7HOU57Y DELETE,则表示您是删除那个元素.
If you use example/resources/7HOU57Y DELETE, that means you are deleting that element.
我正在做一个网站,注意不是网络服务.
I am doing a WEBSITE, note NOT WEB SERVICE.
我有一个列表,列表中的每个项目都有 1 个复选框.一旦我选择了多个要删除的项目,我将允许用户按下一个名为 DELETE SELECTION 的按钮.如果用户按下按钮,将弹出一个 js 对话框,要求用户确认删除.如果用户确认,则删除所有项目.
I have a list that has 1 checkbox for each item on the list. Once i select multiple items for deletion, i will allow users to press a button called DELETE SELECTION. If user presses the button, a js dialog box will popup asking user to confirm the deletion. if user confirms, all the items are deleted.
那么我应该如何以 RESTFUL 的方式删除多个项目?
So how should i cater for deleting multiple items in a RESTFUL way?
注意,目前用于网页中的 DELETE,我所做的是使用带有 POST 的 FORM 标记作为操作,但包含一个值为 DELETE 的 _method,因为 这是其他人在 SO 中指出的如何对网页进行 RESTful 删除.
NOTE, currently for DELETE in a webpage, what i do is i use FORM tag with POST as action but include a _method with the value DELETE since this is what was indicated by others in SO on how to do RESTful delete for webpage.
推荐答案我认为 rojoca 的答案 是迄今为止最好的.一个细微的变化可能是,取消同一页面上的 javascript 确认,而是创建选择并重定向到它,在该页面上显示一条确认消息.换句话说:
I think rojoca's answer is the best so far. A slight variation might be, to do away with the javascript confirm on the same page, and instead, create the selection and redirect to it, showing a confirm message on that page. In other words:
来自:example/resources/
做一个
带有选择的 ID 的 POST 到:example/resources/selections
POST with a selection of the ID's to: example/resources/selections
如果成功,应该回复:
HTTP/1.1 201 创建,位置标头到:example/resources/selections/DF4XY7
HTTP/1.1 201 created, and a Location header to: example/resources/selections/DF4XY7
在此页面上,您将看到一个 (javascript) 确认框,如果您确认将执行以下请求:
On this page you will then see a (javascript) confirm box, which if you confirm will do a request of:
删除example/resources/selections/DF4XY7
如果成功,应该回复:HTTP/1.1 200 Ok(或任何适合成功删除的内容)
which, if successful, should respond with: HTTP/1.1 200 Ok (or whatever is appropriate for a successful delete)
更多推荐
删除一堆项目的宁静方式
发布评论