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

118
Views
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 answers
Answer question

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 Report
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!