Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
¿Cómo crear un cuadro de confirmación asíncrono a partir de una función ajax en javascript?

Estoy tratando de crear un cuadro de confirmación personalizado que se ejecutará de forma asíncrona desde una función ajax que llamará a un botón Eliminar oculto en el código C# detrás, pero parece que no puedo hacer que espere correctamente. Simplemente quiero que aparezca un cuadro de confirmación y luego esperar para procesar cualquier otra cosa hasta que el usuario haya elegido sí o no. Estoy usando una Promesa para esperar. Sin embargo, no parece estar haciendo nada. El clic del botón Eliminar oculto debería ser lo último que suceda si el usuario ha hecho clic en Sí, pero el código no ingresa a ese bloque. Estoy seguro de que hay algo muy simple que me estoy perdiendo. El siguiente es el código que estoy usando:

 <div id="confirm" class="confirm"> <div class="message">The project name already exists! Do you wish to delete the project?</div> <br /> <div> <button id="true_btn" class="true_btn">Yes</button> <button id="false_btn" class="false_btn">No</button> </div> </div> function checkDirectory(projectName) { var onError = false; $.ajax({ type: 'GET', url: "<%= ConfigurationManager.AppSettings["checkDirUrl"] %>" + "/" + projectName, //async: false, success: async function (result) { if (result === "folder exists") { //if (confirm('The project name already exists! Do you wish to delete the project?')) { if (await deleteDemo() === 1) { alert('After deleteDemo'); $("#<%= btnHiddenDelete.ClientID %>").click(); } else { onError = true; $("#error").text("Project name already exists!"); } } else { window.location = ("/Database.aspx"); } }, error: function (result) { onError = true; $("#error").text("Error accessing project folder!"); } }); return onError; } async function confirmationBox() { return new Promise(function(resolve, reject) { var confirmation_modal = $("#confirm"); var true_el = $("#true_btn"); var false_el = $("#false_btn"); alert('In confirmationBox'); confirmation_modal.show(); true_el.click(function() { alert('yes'); resolve(1); }); false_el.click(function() { alert('no'); resolve(0); }); }); } async function deleteDemo() { var result = await confirmationBox(); alert(result); return result; }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!