Example code is:
开发者_JS百科$db.saveDoc(doc, {
success: function () {
// Do something with the ID.
},
error: function () {
alert("Cannot save the thread.");
}
});
In the success callback function, how do you get the ID of the doc that's just been saved?
Pretty much all jquery.couch functions call the success callback with the data returned from the http request, when you sent a POST /db/doc request,
{"ok":true,"id":"ad5c9fc93ae3b6f5f9809357a30003fe","rev":"1-2a91bdd9ee1e3e5e6302741132d7c415"}
is returned, so
$db.saveDoc(doc, {
success: function (data) {
var id = data.id;
},
error: function () {
alert("Cannot save the thread.");
}
});
精彩评论