How do I return a variable from $.post() in jQuery? Closure variable?
Posted
by James Bao
on Stack Overflow
See other posts from Stack Overflow
or by James Bao
Published on 2010-05-19T20:26:34Z
Indexed on
2010/05/19
20:30 UTC
Read the original article
Hit count: 227
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!
© Stack Overflow or respective owner