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

75
Vistas
Stop infinite page reload when navigating back using ajax

I am using Wordpress along with an ajax theme and I am also using an ajax search plugin.

In order to stop the page being reloaded and continue to use ajax when clicking a search result in the ajax search I have been provided with the following code:

    let dom_observer = new MutationObserver(function(mutation) {
    if ( typeof Pjax != 'undefined' ) {
        let newContent = document.querySelector(".asl_r");
        let pjax = new Pjax({
                   cacheBust: false,
                   elements: "a", // default is "a[href], form[action]"
                   selectors: ["title", "#header nav", "#aside", "#footer", "#content"] 
                });
        pjax.refresh(newContent);
        jQuery('.asl_r .item').off('click.body').one('click.body', function(){
            document.body.click();
        });
    }
});
let container = document.documentElement || document.body,
    config = { attributes: false, childList: true, subtree: true, characterData: false };
dom_observer.observe(container, config);

This works fine, but I have an issue that occurs if you navigate to a page and then hit the back button in a browser

When using the back button the previous page will load ok, but will start to infinitely reload.

If I remove this code I can navigate back fine with no reloading taking place.

I have tried removing cacheBust thinking this could be having an effect, but this makes no change.

If someone with knowledge of js/ajax could provide any advice it would be much appreciated.

Thanks

Edit: Resolved with dev who has provided an alternative solution without need for this code.

about 4 years ago · Juan Pablo Isaza
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