简体   繁体   中英

How do I use a jQueryUI Dialog for confirmation?

I'm trying to use the jQueryUI Dialog to get user confirmation before a database update, but I'm battling to see how I can tell what the user's choice on the dialog is, as all in samples I can find, both buttons just close the dialog, with no persistence of the chosen button. Eg from the jQueryUI sample and docs:

            buttons: {
                'Deactivate the campaign': function () {
                    $(this).dialog('close');
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }

Your calling the same function ( $(this).dialog('close'); ) for both buttons. You need to do somehting more than just close the dialog. You can update a hidden span to pass which button was clicked or just call the DB update from there.

buttons: {
        'Deactivate the campaign': function () {
            //pass the value using a hidden span
            $('#myHiddenControl').val('True');

            //or just call the db update
            $.ajax({/* db call code ommited*/});

            $(this).dialog('close');
        },
        Cancel: function () {
            //pass the value using a hidden span
            $('#myHiddenControl').val('False');
            $(this).dialog("close");
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM