ajaxComplete not being called

13,392

There is no ajaxComplete event handler for the $.ajax object, instead use done or always. There is also the complete event handler but it was deprecated as of jQuery 1.8.

 $(document).ajaxStart(function () {
    console.log("ajax start");
    $("#loading").show();
});

$(document).ready(function () {

    $.ajax({
        type: 'GET',
        url: '@Url.Content("~/Service/listAllDevices")' + '?limit=' + 300 + '&offset=' + 10,
        dataType: 'json',
        async: 'false',
        global: true,
        success: function (listAllDevicesResponse) {
            console.log("ajax done");
            console.log(listAllDevicesResponse);
        },
        always: function() {
          console.log("ajax complete");
          $("#loading").remove();            
        }
    });

});

You can read more about the jQuery $.ajax here.

Share:
13,392
Lord Vermillion
Author by

Lord Vermillion

Updated on June 04, 2022

Comments

  • Lord Vermillion
    Lord Vermillion almost 2 years

    I can't figure out why this isn't working, i've looked at many questions here at stackoverflow but can't find anything wrong with my code.

    I have a #loading div that i want to remove when the ajax call is complete. This is my code and ajaxComplete is never called.

    What am i doing wrong?

     $(document).ajaxStart(function () {
            console.log("ajax start");
            $("#loading").show();
        });
        $(document).ajaxComplete(function () {
            console.log("ajax complete");
            $("#loading").remove();
        });
    
        $(document).ready(function () {
    
    
            $.ajax({
                type: 'GET',
                url: '@Url.Content("~/Service/listAllDevices")' + '?limit=' + 300 + '&offset=' + 10,
                dataType: 'json',
                async: 'false',
                global: true,
                success: function (listAllDevicesResponse) {
                    console.log("ajax done");
                    console.log(listAllDevicesResponse);
                }
            });
    
        });