ReyDev Posted January 2, 2021 Share 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? Link to comment Share on other sites More sharing options...
Miss_B Posted January 2, 2021 Share Posted January 2, 2021 Can you please post here the code? Link to comment Share on other sites More sharing options...
CodingJungle Posted January 2, 2021 Share 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 Link to comment Share on other sites More sharing options...
ReyDev Posted January 2, 2021 Author Share 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 ?! Link to comment Share on other sites More sharing options...
Daniel F Posted January 2, 2021 Share 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 Link to comment Share on other sites More sharing options...
ReyDev Posted January 2, 2021 Author Share 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 Link to comment Share on other sites More sharing options...
Solution bfarber Posted January 4, 2021 Solution Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts