Returning value doesn't work, when returning inside Jquery function. When I return outside Jquery function it doesn't work good, because return doesn't wait for Jquery function, and giving error: Uncaught ReferenceError: result is not defined.
How can I solve this problem? Mby I should make Jquery function named count_with_min_max_val?
//counting precentage function
function count_with_min_max_val(val, perc, min_val, min_val_limit, max_val, max_val_limit, action) {
//ajax data
var json_obj = {};
json_obj.values = {
"action": action,
"value": val,
"percent": perc,
"min_val": min_val,
"min_val_limit": min_val_limit,
"max_val": max_val,
"max_val_limit": max_val_limit
};
var json_obj = JSON.stringify(json_obj);
$.post("pages/calc/calculator.php", {
json_a: json_obj
}).done(function (data) {
result = data;
alert(result); //that works
return result; //doesn't return to main function
});
return result; //return doesnt wait for Jquery function to complete, and showing error
}