Today I'm creating a Javascript function called "sendData".
This is used for ease, instead of writing out a whole ajax statement.
Anyway I know it's asynchronous, I was wondering how I could wait and get the value returned instead of returning nothing. Here is what I have.
function returnData(data)
{
alert(data + " ddd");
return data;
}
function sendData(data,file) {
var a = ""
$.ajax({
url: file,
data: data,
type: "POST",
success: function(newData)
{
a = newData;
}
})
returnData(a);
}
I thought this would work, but it doesn't. Does anyone know how I can wait for it to return or something?
Final Code
function sendData(data,file) {
var a = ""
$.ajax({
url: file,
data: data,
type: "POST",
async:false,
success: function(newData)
{
a = newData;
}
})
return a;
}