Advertisement
Guest User

Ajax.js

a guest
Dec 2nd, 2022
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ajax filtering
  2. $('.cat-list_item').on('click', function(e) {
  3.     e.preventDefault();
  4.     $('.cat-list_item').removeClass('active');
  5.     $(this).addClass('active');
  6.    
  7.     $.ajax({
  8.       type: 'POST',
  9.       url: '/wp-admin/admin-ajax.php',
  10.       dataType: 'json',
  11.       data: {
  12.         action: 'filter_projects',
  13.         category: $(this).data('slug'),
  14.       },
  15.       success: function(res) {
  16.         currentPage = 1;
  17.         $('.post-filter').html(res.html);
  18.         $('.card').each(function(i) {
  19.           // 'i' stands for index of each element
  20.           $(this).delay(i * 400).fadeIn(600);
  21.         });
  22.       }
  23.     })
  24.  
  25.   });
  26.  
  27.   // ajax load more
  28.   let currentPage = 1;
  29.   $('#load-more').on('click', function() {
  30.     currentPage++;
  31.  
  32.     $.ajax({
  33.       type: 'POST',
  34.       url: '/wp-admin/admin-ajax.php',
  35.       dataType: 'json',
  36.       data: {
  37.         action: 'load_more_projects',
  38.         category: $(this).data('slug'),
  39.         paged: currentPage,
  40.       },
  41.       success: function (res) {
  42.         if(currentPage >= res.max) {
  43.           $('#load-more').hide();
  44.         }
  45.         $('.post-filter').append(res.html);
  46.       }
  47.     });
  48.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement