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

- 124,992
- 159
- 614
- 958

- 251
- 1
- 3
- 3
-
3@jldupont: It can be very useful, think about a file manager. – Camilo Martin Dec 15 '09 at 16:54
-
@jldupont I think they mean from a web page. – jpmc26 Sep 18 '15 at 20:00
6 Answers
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);
}
});

- 25,305
- 8
- 78
- 114
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.

- 31,277
- 10
- 71
- 76
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.

- 8,861
- 2
- 30
- 34
I believe that both PUT and DELETE are not implemented (in the case of Prototype) due to flaky browser support.

- 18,438
- 15
- 77
- 121
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.

- 674
- 5
- 13