Skip to content

Instantly share code, notes, and snippets.

@wisnust
Forked from allenbell/pagination.js
Created February 16, 2021 16:42
Show Gist options
  • Select an option

  • Save wisnust/f95e04df7880dba9bd71cadf932e3884 to your computer and use it in GitHub Desktop.

Select an option

Save wisnust/f95e04df7880dba9bd71cadf932e3884 to your computer and use it in GitHub Desktop.

Revisions

  1. @allenbell allenbell created this gist Feb 10, 2016.
    35 changes: 35 additions & 0 deletions pagination.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    jQuery(document).ready(function($){

    $(document).on( 'click touchstart', '#pagination a', function( event ) {

    // Fade out the old content for a smooth transition
    $('#bike-features-inner').fadeOut();

    // The pagination button you clicked will pass the page number back to the callback function
    var page = $(this).attr('href');

    // This will pass the post ID back to the callback function
    var bikeID = $(this).closest('#pagination').find('#bike-id').attr('data-bike-id');

    event.preventDefault();
    $.ajax({
    url: ajaxpagination.ajaxurl,
    type: 'post',
    data: {
    action: 'dl_bike_features', // the name of the function in your php file
    page: page, // access in php function via $_POST['page']
    bikeID: bikeID // access in php function via $_POST['bikeID']
    },
    success: function( result ) {
    // Replace the content of the container div w/ the output from dl_bikeFeatures()
    $('#bike-features-inner').html(result);
    // fade in this content for a smooth transition
    $('#bike-features-inner').fadeIn();
    },
    error: function(MLHttpRequest, textStatus, errorThrown){
    alert('Sorry, something went wrong. Please try again.');
    }
    })
    })

    });