0
I have a list of tasks with checkboxes, which when marked updates, via ajax, the status of the task in the database, what I want to do is return the completion percentage of the list, which is already done in the backend, and also already has a function js called "percentage", the problem is that in checkbox marking Success I would like to take the value of the percentage function, but there is no return.
Ex:
function porcentagem(id) {
$.ajax({
url: 'url',
method:'POST',
dataType: 'JSON',
data: {id: id},
success: function(data) {
if(data.success == 1) {
return data.porcentagem;
}
}
});
}
Success: ajax of the checkbox:
if(data.success == 1) {
var id = $("input[name='id']").val();
alert( porcentagem(id) );
}
The percentage function was set before ajax, and yet the console shows me:
Uncaught Typeerror: percentage is not a Function
Tried to take the return of Ajax in a variable and display after that the variable itself ?
– Bruno
but in this case the variable of the percentage function would not be local?
– Thiago