Skip to content
Advertisement

Delete method with Sweet Alert in Laravel

I’m testing a method using Sweet Alert, to improve the messages issued by the Javascript alert method with the laravel framework.

1 – I downloaded the files sweetalert.css and sweetalert.min.js.

2 – So I connect the files from app.blade.php

JavaScript

3 – I created the delete button using the onclick event of Javascript and the following Sweet Alert function:

JavaScript

4 – This is my method for deleting users from UserController:

JavaScript

5 – The problem occurs when deleting a user, displays the alert message.

Message generated by Sweet Alert

But automatically closes and deletes the user without allowing to take the confirmation actions, whether or not to delete the user, method defined in Sweet Alert.

Someone who can give a help to correct this problem or recommend a better method, since I am using Laravel as Framework.

Advertisement

Answer

You are Performing action on button click irrespective of whether you confirm or cancelled the deletion.

JavaScript

Jquery and Ajax:

JavaScript

And:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement