Using REST to delete a document in CouchDB
You denote a RESTful deletion of a document by sending a HTTP DELETE
request with the ID and revision of the document to be deleted.
How to do it…
Using the HTML from the previous recipe, here's a script that extracts the ID and revision from the form fields, does some simple error checking, and sends a deletion request to the server for the document with the indicated ID and revision:
function doRemove() { id = $('#id').val(); rev = $('#rev').val(); if (id == '') { alert("Must provide an ID to delete!"); return; } if (rev == '') { alert("Must provide a document revision!"); return; } $.ajax({ type: "DELETE", url: "http://localhost:5984/documents/" + id + '?rev=' + rev, }) .done(function(result) { $('#json').html(JSON.stringify(result)); ...
Get JavaScript JSON Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.