javascript - AJAX functions returning values -
this question has answer here:
- how return response asynchronous call? 21 answers
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
Post a Comment