I am trying to solve the problem of assigning values returned from getJSON()
functions to variables, after the getJSON()
has finished.
I think the following resolves the timing issues, but I have run into another problem which is extricating the value returned from the done()
function and assigning it to a variable.
var fn1 = $.getJSON("/path", function(){
});
var h = fn1.done(function (results) {
console.log(results.a_key); // this logs the desired value
console.log(jQuery.type(results.a_key)); // this logs 'string'
return results.a_key;
});
alert(h); // alerts [object Object]
How do I access the returned value of a done()
function that is assigned to a variable?
This is not a timing issue question, it is about how to access the returned value.
If the above is the wrong approach, could somebody demonstrate how they would resolve the issue and assign the result to a variable outside of the function?