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

247
Views
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;
    }
about 4 years ago · Juan Pablo Isaza
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!