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 enumerate CouchDB records

REST semantics dictate that to fetch the full contents of a collection of objects, we just send a GET request to the collection's root. We can do that from a web client to a CouchDB with CORS enabled using jQuery with a single call.

How to do it...

Here's some HTML, jQuery, and JavaScript that enumerate all items in a CouchDB view and shows some of the fields of each objects in an embedded table:

<!DOCTYPE html> <html> <head> <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> </head> <body> <p>Hello world</p> <p> <div id="debug"></div> </p> <p> <div id="json"></div> </p> <p> <div id="result"></div> </p> <button type="button" id="get" ...

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