Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
How to change html Ajax content when clicking on the back button?

I have a search page with filter. When the user change the filter values, I add parameters to the URL to prevent the values if the user refreshed the page

q       = $('#form input[name=q]').val(),
srchtype= $('#filter input[name=srchtype]:checked').val(),
sortBy  = $('#filter select#sortBy').val(),
parameters = "q="+qVal+"&srchType="+srchType+"&sortBy="+sortBy;
history.pushState(null, null, '?'+parameters);

then I get the data using Ajax

$.ajax({
    type: "POST",
    url: url,
    data: parameters+"&_token="+_token
}).done(data => {
    // Javascript Code
});

The problem is that when the user click on the browser's back button, the URL will change to the previous one, but the data on the page will not change.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I tried and it works :D

history.replaceState($('body').html(), null) // store the first body html

q       = $('#form input[name=q]').val(),
srchtype= $('#filter input[name=srchtype]:checked').val(),
sortBy  = $('#filter select#sortBy').val(),
parameters = "q="+qVal+"&srchType="+srchType+"&sortBy="+sortBy;

$.ajax({
    type: "POST",
    url: url,
    data: parameters
}).done(data => {
    // Javascript Code

    history.pushState($('body').html(), null, '?'+parameters); // store the next body html and url
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda