Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda