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

111
Visualizações
location.href load on the current page/previous url

i have the following jquery for onclick code :

function find(){
$.ajax({
    type: "post",
    url: link + 'register/data',
    data: {},
    success: function () {
        window.location.href= "mycontroller/myfunction"
    }
});

}

i want to make the url stays on mycontroller/myfunction everytime they click the button, i tried substring lastindexof but it keeps adding more url everytime i click the button, how do i make the button stays on that whenever i click it? thanks in advance

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Let's pretend you're on http://example.com. You redirect the page to "test", so now you're on http://example.com/test. Now you redirect to "test" again. Uh oh, now you're on http://example.com/test/test. Didn't want that to happen, did you? You redirect it just one more time to "other/test". Oh no, now you're on http://example.com/test/test/other/test!

The way to solve this resides in a single bytes. Change test to /test, so it'll always compare to the base URL instead of the current one.

In your JavaScript:

window.location.href = "/mycontroller/myfunction";

However you click it you'll always be on http://example.com/mycontroller/myfunction.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can change the success function to use window.location.origin like this:

function find(){
  $.ajax({
    type: "post",
    url: link + 'register/data',
    data: {},
    success: function () {
        window.location.href = window.location.origin + "/mycontroller/myfunction"
    }
  });
}
about 4 years ago · Juan Pablo Isaza 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