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

192
Vistas
How to create an asynchronous confirmation box from an ajax function in javascript?

I am trying to create a custom confirmation box that will run asynchronously from an ajax function that will call a hidden Delete button in the C# code behind, but I can't seem to get it to wait properly. I simply want it to bring up a confirmation box and then wait to process anything else until the user has chosen yes or no. I am using a Promise for waiting. However, it doesn't seem to be doing anything. The hidden Delete button click should be the last thing that happens if the user has clicked yes, but the code is not getting into that block. I am sure there is something very simple that I am missing. The following is the code that I am using:

<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
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