The following code has two then()
. There is a $.getJson()
in the first then()
. How to pass the result of $.getJson()
to the parameter x
of the second then()
?
MyPromise
.then(function (i) {
instance = i;
var cookie;
$.getJSON('http://localhost:5000/api/cookie/'+i.address+'/articleid/'+id, function(x){
cookie = x;
});
console.log('[' + cookie + ']'); // undefined, it will get right value if put the two lines in .done() but then cannot return the cookie to next then().
return cookie;
})
.then(x => {
console.log("need to get cookie here: "+x); // x is undefined
});