Dynamically displaying content from another page

0

I would like to be able to display various content (from other pages) on a single page for each click on a link or button that the user gives. I know that one of the solutions would be to use AJAX, but the problem is that when I give a refresh , the content that is visible at the moment adds up and returns that of the main page, what I would like is to remain in the same page with the same content before refresh .

The Javascript code I use is this:

$.ajax({
    url : './pagina.php',
    type : 'POST',
  cache: false,
    data : 'dado=' + dado,
    beforeSend: function () {},
    complete: function () {},       
    success: function(data){
       $('#showInfo').html(data); //      $('# showInfo').show();
    },
    error: function(){
       // comandos a serem executados caso Houver algum 
    });        

Another one I've also used is:

  $.get("pautas.php?acao=1", function( data ) {
    $('#content').html(data);
  });

Can anyone please give me a tip ??

    
asked by anonymous 19.04.2017 / 01:07

1 answer

0

Each click that the user gives adds a hash in the url. This way you will have control of the pages that that user has already passed and will know how many pages to load.

var page = 0;

$('button.next').click(function(event) {
    event.preventDefault();
    window.location.hash = page+=1;
});

When the page loads you check if it has a hash, if you have it you will have to load the amount of information that that hash represents. If each page you load 10 data and the user gave reload in # 3 you need to print with ajax 30 results.

To get the hash of the url just use

window.location.hash 
    
19.04.2017 / 05:58