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

StackOverflow https://stackoverflow.com/questions/5876867

  •  28-10-2019
  •  | 
  •  

Question

Example code is:

$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?

Was it helpful?

Solution

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.");
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top