I found this and this demo, replacing pages with Ajax without reloading. but unfortunately, when I refresh the page. Data back from the first page again. How can I make if I had chosen page 4 and refresh the page. I'm still on page 4?
I read of some articles, I have to use cookies. But I do not understand how. Then, how?
This code jquery
$(document).ready(function() {
$("#results" ).load( "fetch_pages.php");
$("#results").on( "click", ".pagination a", function (e){
e.preventDefault();
$(".loading-div").show();
var page = $(this).attr("data-page");
$("#results").load("fetch_pages.php",{"page":page}, function(){
$(".loading-div").hide();
});
});
});
What like this? document.cookie = "page=" + $(this).attr("data-page");
===== Update =====
<script type="text/javascript">
$(document).ready(function() {
if(typeof(Storage) !== "undefined") {
if (sessionStorage.clickcount) {
$("#results").load("fetch_pages.php",{"page":sessionStorage.clickcount}, function(){
$(".loading-div").hide();
});
} else {
$("#results").load("fetch_pages.php");
}
} else {
$("#results").load("fetch_pages.php");
}
$("#results").on( "click", ".pagination a", function (e){
e.preventDefault();
$(".loading-div").show();
var page = $(this).attr("data-page");
sessionStorage.clickcount = page;
$("#results").load("fetch_pages.php",{"page":sessionStorage.clickcount}, function(){
$(".loading-div").hide();
});
});
});
</script>