Use function within the ajax response success

0

I have a list of tasks with checkboxes, which when checked updates via ajax the status of the task in the database, what I want to do is to return the completion percentage of the list, which is already done in the backend, and also already has a js function called "percentage", the problem is that in the success of the checkbox I would like to get 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: checkbox ajax:

                if(data.success == 1) {
                    var id = $("input[name='id']").val();
                    alert( porcentagem(id) );
                }

The percentage function was set before ajax, and even then the console shows me:

  

Uncaught TypeError: percentage is not a function

    
asked by anonymous 28.07.2017 / 15:57

0 answers