the call to .done in ajax is not completed

2

I have the following function

function deleteItem(item_id) {
    var invoiceData = {
        'idt_id': item_id,
        'inv_id': $('#inv_id').val(),
        'inv_number': $('#inv_number').text(),
    };

    $.ajax({
        type: 'GET',
        url: 'invoiceDetailDelete.php',
        data: invoiceData,
        dataType: 'json',
        encode: true
    })
        .done(function (invoiceData) {
            if (invoiceData.success) {
              alertify.success(invoiceData.message);
              // mas codigo...
            }
            else {
              alertify.error(invoiceData.message);
            }
        })
        .fail(function () {
           alertify.error(invoiceData.message);
        })
    }

the file invoiceDetailDelete.php deletes the record correctly and returns ...

$invoiceData ['success'] = true;
$invoiceData ['message'] = "Item Borrado con Exito!";

echo json_encode($invoiceData);

value returned is correct

{"success":true,"message":"Item Borrado con Exito!"}

but the .done is never executed, the code never goes through there.

What could be the problem?

Thanks for your comments.

    
asked by Juan Carlos 11.04.2018 в 16:08
source

1 answer

0

One option is to use the .success . If not, depending on the jQuery version the function you want to use is called .complete or .done

Edit:

In older versions of jQuery, if you use the .done return function, but it must have become obsolete. Now use .complete , which is the same as .done , in fact the jQuery documentation comes out only complete :

  

complete Type : Function (jqXHR jqXHR, String textStatus) A function   to be called when the request finishes (after success and error   callbacks are executed). The function gets passed two arguments: The   jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string   categorizing the status of the request ("success", "notmodified",   "nocontent", "error", "timeout", "abort", or "parsererror"). As of   jQuery 1.5, the complete setting can accept an array of functions.   Each function will be called in turn. This is an Ajax Event.

Source: link

For your code, just replace the .done with .complete:

 $.ajax({
        type: 'GET',
        url: 'invoiceDetailDelete.php',
        data: invoiceData,
        dataType: 'json',
        encode: true
    })
        // .complete
        .complete(function (invoiceData) {
            if (invoiceData.success) {
              alertify.success(invoiceData.message);
              // mas codigo...
            }
            else {
              alertify.error(invoiceData.message);
            }
        })
        .fail(function () {
           alertify.error(invoiceData.message);
        })
    }
    
answered by 11.04.2018 в 16:35