EDITED I have readed the answer suggested as duplicate, but I'm asking one more level. I created my answer based on what I had learn searching previously and the duplicate one bring me to my question.
I've got this function that is working
function validateLimit(dia, hora, cel, vit, kg) {
var params = 'cel='+cel;
params += '&viti='+viti;
params += '&dia='+data[2]+"-"+data[1]+"-"+data[0];
params += '&hora='+hora;
params += '&kg='+kg;
function testAjax(handleData) {
$.ajax({
type: "POST",
url: "recheck-limit.php",
data: params,
datatype: "json",
success: function(d) {
handleData(d);
}
});
}
testAjax(function(output) {
var data = JSON.parse(output);
if(data.disponible == true) {
return "1234";
} else {
return "4321";
}
});
return "aser";
}
I call it from outside like that
hay_dispo = validateLimit(dia, hora, cel, viti, kg);
But I don't know how to receive the value "1234" or "4321" from inside textAjax function, I can return "aser", but can't get the values I need depending on the value of data.disponible. Thank you