Can I listen to a specific element on ajaxComplete instead of 'document'?

前端 未结 3 1857
闹比i
闹比i 2020-12-12 02:39

Good morning,

I am using the jQuery ajaxComplete Function and I wonder if it would be possible to use it on a specific element (div)?

Example:



        
3条回答
  •  悲哀的现实
    2020-12-12 03:27

    yes, you can add specified option for $.ajax action, ie:

    $.ajax({
        my_option : 'somevalue',
        complete: function(){
            //..your complete logic
        }
    });
    

    and then:

    $(document).ajaxComplete(function(event,xhr,options){
       //if(options.my_option == 'somevalue') { or:
         if(options.my_option) {
              //..your logic
         }
    });
    

    good luck :)

提交回复
热议问题