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 search CouchDB

Using REST to search CouchDB uses a view with a map to create your index, which you insert once, and then a GET HTTP request.

How to do it...

We can modify the previous doGet function to search for a particular call sign, like this:

function doGet(call) { $.ajax({ type: "GET", url: "http://localhost:5984/documents/_design/stations/_view/byCall" + (call != null & call != '') ? ( '?key=' + call ) : '' ), dataType:"json", }) .done(function(result) { $('#json').html(JSON.stringify(result)); var resultHtml = '<table><tr><td><b>id</b></td>'; resultHtml += '<td><b>revision</b></td><td><b>call</b></td>'; resultHtml += '<td><b>lat</b></td><td><b>lng</b></td></tr>'; for(var i = 0; i < result.rows.length; i++) { var item = result.rows[i] ...

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