I have a document in my cloudant db with _id
of mittens13
. I tried to query it and alert, one in the query statement and another one outside the query statement.
However, the one outside the query statement were called first and it gave an alert of undefined
and then it gave another alert hello
which was the item in the doc. May I know why?
Javascript code
function queryDB() {
var price;
db.get("mittens13", function (err, response) {
console.log(err || response);
alert(response.title);
price = response.title;
});
alert(price);
}
Details of the doc in my db
{
"_id": "mittens13",
"_rev": "1-78ef016a3534df0764bbf7178c35ea11",
"title": "hello",
"occupation": "kitten123"
}