Jump to content

How to confirmedDelete() in Ajax


Go to solution Solved by bfarber,

Recommended Posts

Posted

I want to delete some data from DB using ajax , In normal case ,I use confirmDelete() to confirm but in ajax , it does not work. How can I do it, confirm and delete?

Posted
                ips.ui.alert.show({
                    type: 'confirm',
                    icon: 'question',
                    message: ips.getString('some_message_string'),
                    buttons: {
                        ok: ips.getString('ok'),
                        cancel: ips.getString('cancel'),
                    },
                    callbacks: {
                        ok: function (e) {
                            
                        },
                    },
                });

you can use the ips.ui.alert, put the ajax callback inside "ok" that actually sends the ajax request for delete.

Posted
23 minutes ago, CodingJungle said:

                ips.ui.alert.show({
                    type: 'confirm',
                    icon: 'question',
                    message: ips.getString('some_message_string'),
                    buttons: {
                        ok: ips.getString('ok'),
                        cancel: ips.getString('cancel'),
                    },
                    callbacks: {
                        ok: function (e) {
                            
                        },
                    },
                });

you can use the ips.ui.alert, put the ajax callback inside "ok" that actually sends the ajax request for delete.

I do exactly that.
But the problem is using the confirmDelete() method. That means there is no need to use this method in the controller ?!

Posted (edited)
1 hour ago, Daniel F said:

what's in your callback?

I would suggest to take a look at the Request:.confirmedDelete function to see what it is actually doing;)

Thanks.

I think, after confirmation by ips.ui.alert.show, I should add this query (wasConfirmed = 1) to my ajax URL.

I tested. it works. That is correct ?

Edited by ReyDev
  • Solution
Posted

Adding that parameter will effectively tell the backend confirmedDelete() method that the request was confirmed.

The typical manner of doing this is to add the data-confirm attribute to the link, and then call confirmedDelete() on the backend. Don't forget to use a CSRF check if appropriate (which is most likely the case if you are deleting something through a GET request).

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...