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

99
Views
Keep original url for pushstate

I use the following function:

$( document ).ajaxComplete(function() {
     var currenturl = window.location.href;
     var decodedUri = decodeURIComponent(currenturl);

    var decodedUri2 =decodedUri.replace("&manufacturer[]=","/").replace("&page=","/").replace("&sort=","/").replace("&order=","/");
     history.pushState("", "", decodedUri2);

});

I need somehow at each ajax completion to change original url and not previously changed url through pushState.

With the function above at first ajax completion pushState does the job but on next ajax completion pushState decodedUri2 tries to replace from changed url but i need every time to change the original url and pushState the result. Is that possible?

Any ideas of achieving this?

Thank you!

EDIT: Rephrase of the question. Each time an ajax completes, some attributes are added to the URL and i need to replace those attributes. And again the same with each ajax request. So actually i need somehow each time an ajax completion is done to pushState the current URL after ajax completion but from original state.

EXAMPLE: http://ocdemo.eu/desktops.

If you select filters from left column each time url is changing with ajax. So each time i need the shown url to be replaced with something else

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

For anyone searching this, who want to apply pushState without updating the page URL. You can omit the param entirely, as stated in the docs:

https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

Both will work:

history.pushState("", "");
history.pushState("", "", "");

If you're looking to change a URL param on AJAX call in the current URL, theres plenty of discussion on the thread:

How to replace url parameter with javascript/jquery?

about 4 years ago · Santiago Trujillo Report

0

You would have to capture that url to a variable and use that:

var initialUrl;

$( document ).ajaxComplete(function() {
     var currenturl = window.location.href;
     if (!initialUrl) {
       initialUrl = decodeURIComponent(currenturl);
     }

    var decodedUri2 =initialUrl.replace("&manufacturer[]=","/").replace("&page=","/").replace("&sort=","/").replace("&order=","/");
     history.pushState("", "", decodedUri2);

});
about 4 years ago · Santiago Trujillo 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!