How to call .ajaxStart() on specific ajax calls

前端 未结 10 827
孤独总比滥情好
孤独总比滥情好 2020-11-28 03:47

I have some ajax calls on the document of a site that display or hide a progress bar depending on the ajax status

  $(document).ajaxStart(function(){ 
              


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 04:11

    2018 NOTE: This answer is obsolete; feel free to propose an edit to this answer that will work.

    You can bind the ajaxStart and ajaxStop using custom namespace:

    $(document).bind("ajaxStart.mine", function() {
        $('#ajaxProgress').show();
    });
    
    $(document).bind("ajaxStop.mine", function() {
        $('#ajaxProgress').hide();
    });
    

    Then, in other parts of the site you'll be temporarily unbinding them before your .json calls:

    $(document).unbind(".mine");
    

    Got the idea from here while searching for an answer.

    EDIT: I haven't had time to test it, alas.

提交回复
热议问题