I'm having trouble storing an Ajax response into a variable. Here's my code so far:
function bbl(phrase) {
var lp;
$.post(
'babelJS.php',
{"phrase" : phrase},
function (data){
lp = data.lp;
$("#test1").html(lp);
},
'json'
);
$("#test2").html(lp);
}
The div test1 is correctly field but not test2... Why wouldn't lp survive after the $.post section?
Thanks!
Update : I would also want bbl() to return lp...
Update 2 :
I have no more luck with the following, which comes from the FAQ whose link is in the first comment to this post.
function getBbl(phrase,callback) {
$.post(
'babelJS.php',
{"phrase" : phrase},
function (data){
callback(data.locphrase);
},
'json'
);
}
function bbl(phrase) {
var lp
getBbl(phrase,function(locphrase){
lp = locphrase;
});
return lp;
}