I’m working in PHP LARAVEL , what i want is a toastr to delete an item from database.
So when the button is clicked to delete, the toastr should ask “Are you sure to delete?” in ajax.
If selected “OK” the data should be deleted, if selected “Cancel” the data should not be deleted.
How to accomplish this?
Below is my ajax code:
//to unfollow feed
$('#following').click(function (e) {
e.preventDefault();
var formData = $("#unfollowFeed").serialize();
$('.error-msg').html('');
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: baseUrl + 'unfollow',
type: 'POST',
data: formData,
success: function (data) {
var id=$('#feed_id').val();
$("#feedId li[feed-id=" + id + "]").remove(); //to remove <li> of removed feed from sidebar.
toastr.error('The feed was removed.');
$('#follow').show();
$('#following').hide();
}
});
});
This is my view part:
<a href style="{{ $status == 0 ? 'display:none;' : '' }}" class=" btn btn-sm btn-primary following" id="following" >{{ __('Following') }}</a>
Can anyone help me with this?
3
Answers
You can use the inbuilt confirm box:
You can use Sweetalert of bootstrap
You can use sweetalert for this purpose.
Sweet alert docs
Add this cdn
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
then