Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

73
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!