开发者

How do you get a document ID in the success callback when using jquery.couch.saveDoc?

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.");
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜