javascript - AJAX functions returning values -


this question has answer here:

i have following function can't seem returneddata = result set value. if include alert(result) in same location, popup displays string i'm looking correctly.

is there i'm missing here? had thought because declared variable returneddata outside function accessible everywhere?

function ajaxprocesstwovariables(var1, var2) {     var v1 = var1,         v2 = var2;         var returneddata;     $.post(         processinglocation, {              data1: v1,             data2: v2          },         function (result) {             returneddata = result; // *<- doesn't work*             // alert(result); // *<-this works*         }     );     return returneddata; }  var returnedinfo = ajaxprocesstwovariables(var1, var2); $('body').append(returnedinfo); 

$.post run asynchronously. once line run, request made in background, , hit return line of ajaxprocesstwovariables. attempting use returneddata before set in success function of $.post.


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -