eCom limit for Ajax Calls?

TradingboTradingbo Member Posts: 30
edited May 16 in Theme and Design

Hi Support,

We've adapted the following Ajax snippet to add products to customer Wishlists:

$('.static-product-wrap, .productpage').on('click', '.wishlist[data-wishlist]', function(e)
  {
    e.preventDefault();
    
    // if logged in
    if( theme.page.account ) {
         
    var button = $(this);
    
    button.html('<i class="fas fa-spinner fa-spin"></i>');
    button.toggleClass('in-wishlist');
    
    $.ajax({
      url: $(this).attr('href'),
    }).done(function(data)
    {
      if( isIE() && !theme.shop.ssl )
      {
        location.reload();
        return true;
      }
      
       button.html('<i class="heart-icon"></i>');
      
      $('.tb-wishlist').html( $(data).find('.tb-wishlist').html() );
      $('.header-heart.wishlist').html( $(data).find('.header-heart.wishlist').html() )
      
    })
    
    }
    
  });

It reads in your documentation that making multiple Ajax calls in a short period could see users banned from shops?

This snippet is based off user input, sending ajax href="account/wishlistAdd/" requests when clicked.

Would this be acceptable use of Ajax in this context? and if no, why not?

Best wishes,

2 comments

  • MilesbdMilesbd Moderator, Lightspeed Staff Posts: 25 moderator

    Hi @Tradingbo !


    Triggering an AJAX request based off of user input/action is one of the preferred methods of usage, as it deferred the AJAX request until needed. In this scenario, it is unlikely that any user through navigation (i.e. clicking) would be able to exceed the limits of front-end AJAX requests.

    The documentation referencing multiple AJAX requests in a short period is in the context of the front-end api limit (i.e. the data that is retrievable via AJAX), as there are safeguards to avoid too many requests. This limit lies in the multiple requests per second region.


    Happy coding!

  • TradingboTradingbo Member Posts: 30

    Hi Miles,

    Brilliant, thanks for confirming!

Sign In or Register to comment.