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

322
Visualizações
Why cannot use findOne() function in scripts?
<button class="button is-link" type="submit"
                                onclick="matching('<%= product.id %>')">Define</button>

The HTML of the button.

<script>
    async function matching(productID) {
        var r = confirm("Define preference?");

        if (r) {
            alert("testing1")
            
            var thatProduct = await PriceTracker.findOne(productID);
            
            alert("testing2")

            if (thatProduct) {
                alert("Have that product");
                location.assign("/");
            } else if (response.status == 409) {
                var e = await response.json();
                alert(e);
            } else if (response.status == 404) {
                var e = await response.json();
                alert(e);
            }
        } else {
            alert(response.statusText);
        }
    }
</script>

This is the code for a matching function with the sails framework.

When I click a button, the matching function will be called.

The confirm box can be displayed. When I click 'ok', the alert message of "testing1" can also be displayed, while the second alert message "testing2" could not display, and hence the "if condition" cannot be reached as well.

How can I get that product from my database for further usage?

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

0

await won’t work in the top-level code

Change your matching function into this

var matching = (async (productID) => {
    try {
       ...    } 
    catch (e) {
      // handle the error
      ...
    }
})();
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