How do I show a confirmation dialog before submitting a form using the jQuery ajax method?

Question!

I am using jquery ajax to delete a customer from a table. How would I show a confirmation box before submitting the form? I would preferably like to use jQuery's dialog.

I have seen questions like this before but none of them have helped.

This is my code:

    $.ajax({
        type: "POST",
        url: "delete/process.php",
        data: "delcustomerid="+ delcustomerid,
        success: refreshTable
    });


Answers

You need to create a function that makes the call you show after checking for user input.

eg:

function DeleteWithCheck() {
  if (confirm("Are you sure you want to delete customer " delcustomerid.ToString()))
  {
    $.ajax({
      type: "POST",
      url: "delete/process.php",
      data: "delcustomerid="  delcustomerid,
      success: refreshTable
    });
  }
  else
    alert("Aborted");
}

Call this function when you want to do the delete.

By : Hogan


This video can help you solving your question :)
By: admin