I am having trouble passing data retrieved from a $.post() function to use in other places in my code. I want to save the data as a variable and use it outside of the post() function. This is my code:
var last_update = function() {
$.post('/--/feed',
{func:'latest', who:$.defaults.login},
function($j){
_j = JSON.parse($j);
alert(_j.text); // This one works
});
}
alert(_j.text); // This one doesn't
};
last_update(); //run the function
Please help!
If you want to access the data value outside of the ajax request callback, you will need to place that code in a function, and call it from the success callback.
Essentially the same as placing the code in the callback, but can be useful if you have a bit of code that is reused elsewhere.