weixin_33698043 2014-09-11 13:34 采纳率: 0%
浏览 85

没有被调用ajaxComplete

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);
            }
        });

    });
  • 写回答

2条回答 默认 最新

  • weixin_33693070 2014-09-11 13:53
    关注

    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.

    评论
  • 零零乙 2016-01-19 12:08
    关注

    I am not quite sure why your complete function is not called, however I would recommend using stop. ajaxComplete is called everytime an INDIVIDUAL ajax request finished. ajaxStop is called when ALL requests have finished. Like so:

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

    References:

    https://api.jquery.com/ajaxStart/

    https://api.jquery.com/ajaxStop/

    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
  • ¥20 求各位能用我能理解的话回答超级简单的一些问题
  • ¥15 yolov5双目识别输出坐标代码报错
  • ¥15 这个代码有什么语法错误
  • ¥15 给予STM32按键中断与串口通信
  • ¥15 使用QT实现can通信
  • ¥15 关于sp验证的一些东西,求告知如何解决,
  • ¥35 关于#javascript#的问题:但是我写的只能接码数字和字符,帮我写一个解码JS问题
  • ¥15 prophet运行报错,如何解决?
  • ¥15 用GPU跑pytorch搭建的LSTM的时候出现了奇怪的报错