Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
ReyDev Posted January 2, 2021 Posted January 2, 2021 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?
CodingJungle Posted January 2, 2021 Posted January 2, 2021 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. Miss_B 1
ReyDev Posted January 2, 2021 Author Posted January 2, 2021 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 ?!
Daniel F Posted January 2, 2021 Posted January 2, 2021 what's in your callback? I would suggest to take a look at the Request:.confirmedDelete function to see what it is actually doing;) ReyDev 1
ReyDev Posted January 2, 2021 Author Posted January 2, 2021 (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 January 2, 2021 by ReyDev
Solution bfarber Posted January 4, 2021 Solution Posted January 4, 2021 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). ReyDev 1
Recommended Posts