简体   繁体   中英

jquery.couchdb.js Ajax success/error not being called

I'm using jquery.couchdb.js to query my CouchDB database. The view I want to query has both map and reduce functions within. When sending the basic query as shown below:

$(document).ready(function() {

   view_name = db_name+'/jobs_by_mod_stat'
   options = {'group': 'true' , 'reduce': 'true' };

   mod_stat = {};

   $db.view(view_name , {
     success: function(data) {
        console.log(data)
        for (i in data.rows) {
           console.log(data.rows[i].value);
        }
    },
    error: function(e) {
      alert('Error loading from database: ' + e);
    }
  });

});

I see a sensible log for the data, indicating the query has been successful. However, changing the line:

   $db.view(view_name , {

To

   $db.view(view_name , options, {

I don't get a success outcome from the Ajax query, but an error message is not shown either. Firebug shows the query being sent, and the JSON data returned looks sensible:

{"rows":[
{"key":["template","completed"],"value":2}, {"key":["template","running"],"value":2}, {"key":["template","waiting"],"value":6}
]}

But the success function is not entered. Any ideas why I'm seeing this behaviour, I did wonder if it's a bug in jquery.couch.js (I have couchdb 1.1.0).

Cheers.

I've had a bit of trouble myself with the list function, until I went and looked through the source code of jquery.couch.js (the online documentation I found at http://bradley-holt.com/2011/07/couchdb-jquery-plugin-reference/ seems to be outdated).

Basically, the parameters for view and list are different, the list having an extra parameter for the options, instead of having everything under the same parameter as with views.

View:

$.couch.db('yourdb').view('couchapp/' + viewName, {
    keys: ['keys here'],
    success: function (data) {

    }
});

List:

$.couch.db('yourdb').list('couchapp/' + listName, viewName, {
    keys: ['keys here']
}, {

    success: function (data) {

    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM