1

This is the first time I'm use jQuery dialog_modal confirmation. I want to use this before deleting data inside ajax function. I'm still confused how to put this script correctly.

Before using this dialog I have some script like:

 $('#delete').click(function() {
          var params = $('#deletedata').serialize();
          $.ajax({
                   async  : false,
                   cache  : false,
                   data   : params,
                   success: function(res) {
                     //        oTable.fnReloadAjax();
                               $('#recline1').replaceWith("<div id='recline1'></div>");
                               $('#recmodel1').replaceWith("<div id='recmodel1'></div>");
                               $('#tabs').hide();
                               return this;
                               },
                   type   : "POST",
                   url    : "process1.php",
                   });
             return false;
        });

I want if delete is clicked, this dialog will appear then if we choose delete at dialog the deleting process will do, but if we choose no all opened tabs and this dialog will hide.


Edit

I have tried like this, and the dialog confirm can appear:

$('#delete').click(function() {
              $('#dialog-confirm').dialog('open');
              var params = $('#deletedata').serialize();
              ....

I am still confused in how to get button id inside modal confirmation then combine with ajax function?

2 Answers 2

2

You can put your ajax function into the button handler on the dialog initialise. Then open as you describe above.

$('#dialog-confirm').dialog({
    autoOpen: false,
    modal: true,
    buttons: {
        'Delete': function () {
            // Perform the delete
            $.ajax({
                url: "process1.php",
                success: function () {
                    ...
                }
            });
        },
        Cancel: function () {
            $(this).dialog('close');
        }
    }
});
1
  • arghhhhhh...i miss this part...sorry for my limited knowledge..thanks a lot Chris.
    – klox
    Oct 27, 2010 at 8:20
0

Put two buttons inside your dialog-confirm div, 'Ok' and 'Cancel'

Upon clicking the 'Ok' button, call your ajax code (refactor it to a seperate function) and close the dialog.

Upon clicking the 'Cancel' button, just close the dialog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.