Skip to content

Instantly share code, notes, and snippets.

@riedayme
Created June 9, 2022 09:44
Show Gist options
  • Save riedayme/8fe98c3993933b69dede1a296ebc538d to your computer and use it in GitHub Desktop.
Save riedayme/8fe98c3993933b69dede1a296ebc538d to your computer and use it in GitHub Desktop.
<script type='text/javascript'>
$(document).ready(function() {
function PaginationAjax()
{
$('#pagination').on('click','a',function(e){
e.preventDefault();
var href = $(this).attr('href');
$.ajax({
url: href,
type: 'POST',
dataType: 'JSON',
success: function(data) {
// change title
var newTitle = $(output).filter('title').text();
document.title = data.title;
// change url history
history.pushState({}, newTitle ,href);
// refresh data
$('#container-product').html($('#container-product', $(output).wrap("<div/>")).html());
// go to top
$('html, body').animate({ scrollTop: 0 }, 300);
// re-init javascript for new DOM
PaginationAjax();
}
});
});
}
// init for first DOM
PaginationAjax();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment