Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda