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

220
Visualizações
async Javascript functions not running

I have 2 async functions in Javascript. One calls a MVC controller to load a table of "placements", the other deletes an individual placement. The idea is a button is clicked to load the placements in to a modal popup, then each row has a delete button that delete an individual placement, then the same editPlacementHeader function is called after the delete function to re-open the modal and show the table again.

The problem is when I click the button to show the placements, in the console I get the following error -

Uncaught SyntaxError: await is only valid in async functions, async generators and modules

As far as I can tell, the function is async.

If I remove all async and awaits from the JS code, the modal loads, a day is deleted but the modal isnt closed and re-opened, unless i put a breakpoint on the C# code that loads the data to "pause" then it would work.

JS Code -

async function editPlacementHeader(id) {
    let e = $.Event();

    e.preventDefault();

     $("#EditPlacementHeaderPopup").modal("hide");
     $("#EditPlacementPopup").modal("hide");

      await $.ajax({
          url: '/WeeklyPlacement/EditPlacementHeader?bookingId=' + id,
          type: 'POST',
          dataType: 'html',
           contentType: "application/json; charset=utf-8",
           success: function(response) {
                $("#dvEditPlacementHeaderPartial").html(response);
                $("#EditPlacementHeaderPopup").modal("show");
             }
         });
};

async function deleteDay(id, bookingId) {
    let e = $.Event();

    e.preventDefault();

    $.ajax({
        url: '/WeeklyPlacement/DeletePlacementDay?id=' + id,
        type: 'POST',
        dataType: 'html',
        contentType: "application/json; charset=utf-8",
        success: function(response) {
            $("#EditPlacementHeaderPopup").modal("hide");
            $("#EditPlacementPopup").modal("hide");

            toastNotifySuccess("Day deleted successfully", 1000);

            await editPlacementHeader(bookingId);
        }
    });
};

HTML to open the placement -

@mon.Name

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

0

You have an anonymous function in your success callback that isn't async, but using await inside of it. Either remove the "await" before calling editPlacementHeader or make your success callback async, and it should work.

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