Jquery ajaxStart doesnt get triggered

前端 未结 3 669
不思量自难忘°
不思量自难忘° 2020-12-09 17:21

This code

$(\"#loading\").ajaxStart(function() {
        alert(\"start\");
        $(this).show();
    });

in my mark-up

&l         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 18:12

    Starting jQuery 1.9, AJAX events should be attached to document only.

    Refer migration guide. http://jquery.com/upgrade-guide/1.9/#ajax-events-should-be-attached-to-document

    As of jQuery 1.9, the global AJAX events (ajaxStart, ajaxStop, ajaxSend, ajaxComplete, ajaxError, and ajaxSuccess) are only triggered on the document element. Change the program to listen for the AJAX events on the document. For example, if the code currently looks like this:

    $("#status").ajaxStart(function() { 
       $(this).text("Ajax started"); 
    });
    

    Change it to this:

    $(document).ajaxStart(function() {
       $("#status").text("Ajax started");
    });
    

提交回复
热议问题