I have the following function but I can't seem to get returnedData = result
to successfully set the value. If I include alert(result)
in the same location, the popup displays the string I'm looking for correctly.
Is there something I'm missing here? I had thought because I declared the variable returnedData
outside the function it would be accessible everywhere?
function AJAXprocesstwoVariables(Var1, Var2) {
var V1 = Var1,
V2 = Var2;
var returnedData;
$.post(
processinglocation, {
data1: V1,
data2: V2
},
function (result) {
returnedData = result; // *<- this doesn't work*
// alert(result); // *<-this works*
}
);
return returnedData;
}
var ReturnedInfo = AJAXprocesstwoVariables(Var1, Var2);
$('body').append(ReturnedInfo);