Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda