There I had a problem with ajax pagination with HTML API Pushstate.
So, this is my code:
<ul class="small">
<li>
<p>a</p>
</li>
</ul>
<ul class="paging">
<li><a href=/page2>2</a></li>
<li><a href=/page3>3</a><li>
<li><a href=/page4>4</a><li>
</ul>
$(document).ready(function() {
if (window.history && history.pushState) {
historyedited = false;
$(window).on('popstate', function(e) {
if (historyedited) {
loadProducts(location.pathname + location.search);
}
});
doPager();
}
});
function doPager() {
$('.paging li a').click(function(e) {
e.preventDefault();
loadProducts($(this).attr('href'));
history.pushState(null, null, $(this).attr('href'));
historyedited = true;
});
}
function loadProducts(url) {
$('.small li').empty().load(url + ' .small', function() {
doPager();
});
}
It is working good at first click, but when I click 2, or 3, or 4 times the problem cames up. It makes multiple Ajax request and things are getting worser. What is wrong with my code?