O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required