DELETE
request to the passed URL.XMLHttpRequest
web API to make a DELETE
request to the given url
.onload
event, by running the provided callback
function.onerror
event, by running the provided err
function.err
to log the request to the console's error stream by default.const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest();
request.open('DELETE', url, true);
request.onload = () => callback(request);
request.onerror = () => err(request);
request.send();
};
httpDelete('https://jsonplaceholder.typicode.com/posts/1', request => {
console.log(request.responseText);
}); // Logs: {}
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️