How can I send a http delete request from browser?

偶尔善良 提交于 2019-11-27 17:26:05

问题


Is there a way to send a DELETE request from a website, using xmlhttprequest or something similar?


回答1:


As someone mentioned above, jQuery will do this for you, via the following syntax:

$.ajax({
    type: "DELETE",
    url: "delete_script.php",
    data: "name=someValue",
    success: function(msg){
        alert("Data Deleted: " + msg);
    }
});



回答2:


You can test if your browse has DELETE implemented here

Supposing req is a XMLHttpRequest object, the code would be req.open("DELETE", uri, false);




回答3:


This can be done with jQuery, if you don't mind the dependence on a framework. I believe jQuery uses XmlHttpRequest to perform this action. You'd use the $.ajax function with the type parameter set to DELETE.

Please note that not all browsers support HTTP DELETE requests.




回答4:


I use fetch API on one of the projects:

fetch(deleteEndpoint, {
  method: 'delete',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({id: id, token: token})
})

I have deleteEndpoint, id and token previously defined.




回答5:


I believe that both PUT and DELETE are not implemented (in the case of Prototype) due to flaky browser support.




回答6:


You can use php to do this:

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.



来源:https://stackoverflow.com/questions/1908693/how-can-i-send-a-http-delete-request-from-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!