datahub/lists/urlencode.js
2011-04-29 16:27:45 -07:00

23 lines
565 B
JavaScript

/**
* Returns the urlencoded version of the view value
*
* @author Max Ogden
*/
function(head, req) {
// Send the same Content-Type as CouchDB would
if (req.headers.Accept.indexOf('application/json')!=-1)
start({"headers":{"Content-Type" : "application/json"}});
else
start({"headers":{"Content-Type" : "text/plain"}});
if ('callback' in req.query) send(req.query['callback'] + "(");
var rows = []
while (row = getRow()) {
rows.push(row.value)
}
send(escape(JSON.stringify(rows)));
if ('callback' in req.query) send(")");
};