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

279
Visualizações
Can I use thymeleaf syntax inside of javascript code?

Here is the part of the code that I try to take out to .js file

$(document).ready(function () {
$("#buttonCancel").on("click", function () {
    window.location = "[[@{/users}]]"; 
});
});

and link to this file from .html right before close body tag:

<script type="text/javascript" th:src="@{/js/userForm.js?v=1}"></script>

If I click "Cancel" I have an error 400. Yes, I can use "window.location = "/myweb/users";" and it works well. But I am curious if there any way to use th-syntax in javascript file?

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

0

As alternative, you could create a hidden link in your HTML, and then use it in your script:

HTML:

<a id="cancelAction" style="display:hidden" th:href="@{/users}"></a>

JavaScript:

$(document).ready(function () {
    $("#buttonCancel").on("click", function () {
        $("#cancelAction").click();
    });
});
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