示例代码是:
$db.saveDoc(doc, {
success: function () {
// Do something with the ID.
},
error: function () {
alert("Cannot save the thread.");
}
});
在成功回调函数中,如何获取刚刚保存的文档的ID?
答案 0 :(得分:4)
当您发送POST / db / doc请求时,几乎所有jquery.couch函数都使用http请求返回的数据调用成功回调,
{"ok":true,"id":"ad5c9fc93ae3b6f5f9809357a30003fe","rev":"1-2a91bdd9ee1e3e5e6302741132d7c415"}
返回,所以
$db.saveDoc(doc, {
success: function (data) {
var id = data.id;
},
error: function () {
alert("Cannot save the thread.");
}
});