AjaxComplete() for only a function, not a selector

2019-08-17 04:03发布

Hi i have a AjaxComplete function in a js file that fires several clicks for different buttons, but all refered to the same selector.

I need a different ajaxComplete function for every click function, is this possible?

jQuery(document).ready(function(){
var number = 1;
///////////////////////////////////////////////////
 /* The button to see the single portfolio items */
jQuery(document).on('click','.cover a, .prev_mimo, .next_mimo',function (coverclick){

    coverclick.preventDefault();
    coverclick.stopPropagation();
    coverclick.stopImmediatePropagation();
    number ++;
    /* Get the link */
    var coverlink = jQuery(this).attr('href');
    jQuery('.loadmask').show();
    jQuery('.loadmask-msg').show();
    jQuery('.upperdiv').animate({height : 'hide', opacity : 'hide', easing: 'EaseOutBounce'},'slow', function(){                                        jQuery('.upperdiv').html('');});
    jQuery('.upperdiv').load(coverlink+' .loading_div');


    return false;

});
jQuery('.upperdiv').ajaxComplete(function() {
        var  slideClass = 'all_project_images' + number;
        var  dentroClass = '.' + slideClass;
        jQuery('html,body').stop().animate({
                    scrollTop: jQuery(this).offset().top},
                    'slow');
        jQuery('.post_nav_portfolio').show();
        jQuery('.slideshow ul').removeClass().addClass(slideClass);
        jQuery(dentroClass).stop(false,true).responsiveSlides({
                    auto: true,
                    nav: true,
                    speed: 500});   
        jQuery('.upperdiv').animate({height : 'show', opacity : 'show', easing: 'EaseInBounce'},'slow');
        jQuery('.loadmask').hide();
        jQuery('.loadmask-msg').hide();
        jQuery('.cover').hover(function(){
                jQuery(this).children('.mimo_portfolio_image').stop().animate({opacity : 0.5},'fast');
                    }, function(){
                jQuery(this).children('.mimo_portfolio_image').stop().animate({opacity : 1},'fast');
                    }); 
        jQuery("a[rel^='prettyPhoto']").prettyPhoto();
        jQuery('.slideshow').hover(function(){
                jQuery(this).children('.rslides_nav').show('slow');
                }, function(){
                jQuery(this).children('.rslides_nav').hide('slow');
            });
            console.log(dentroClass);

            });

      });

1条回答
该账号已被封号
2楼-- · 2019-08-17 04:29

inside your ajaxComplete() function you can check which was the original button that initiated the ajax call, by testing out $(this).

Try something like this:

 $('.buttons').ajaxComplete(function(){
      if($(this).hasClass('button1')){
         // do one thing
      }else if($(this).hasClass('button2')){
         // do another
      }
 });

in this case, your buttons should have different classes to describe their actions:

<button class="buttons button1">button1</button>
<button class="buttons button2">button2</button>
查看更多
登录 后发表回答