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

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

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 Denunciar

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