Javascript 如何从浏览器发送http删除请求?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1908693/
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
How can I send a http delete request from browser?
提问by Kalvaresin
Is there a way to send a DELETE request from a website, using xmlhttprequestor something similar?
有没有办法从网站,使用xmlhttprequest或类似的东西发送 DELETE 请求?
回答by Mike Trpcic
回答by jbochi
回答by Tim S. Van Haren
This can be done with jQuery, if you don't mind the dependence on a framework. I believe jQueryuses XmlHttpRequestto perform this action. You'd use the $.ajaxfunction with the typeparameter set to DELETE.
jQuery如果您不介意对框架的依赖,这可以通过 来完成。我相信jQuery用于XmlHttpRequest执行此操作。您将使用参数设置为的$.ajax函数。 typeDELETE
Please note that not all browsers support HTTP DELETE requests.
请注意,并非所有浏览器都支持 HTTP DELETE 请求。
回答by Damjan Pavlica
I use fetch API on one of the projects:
我在其中一个项目上使用 fetch API:
fetch(deleteEndpoint, {
method: 'delete',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id: id, token: token})
})
I have deleteEndpoint, idand tokenpreviously defined.
我有deleteEndpoint,id并且token之前定义过。
回答by robjmills
I believe that both PUT and DELETE are not implemented (in the case of Prototype) due to flaky browser support.
我相信 PUT 和 DELETE 都没有实现(在 Prototype 的情况下),因为浏览器支持不稳定。
回答by MikeEL
You can use php to do this:
您可以使用 php 来执行此操作:
setup your XMLHTTPRequst to call a phpscript that deletes a named file, and then pass the filename that you intend to be removed to the php script and let it do its business.
设置您的 XMLHTTPRequst 以调用删除命名文件的 phpscript,然后将您打算删除的文件名传递给 php 脚本并让它完成它的工作。

