I want to use Sweetalert2 to confirm wether you want to delete a record or not. If you press "DELETE" and there's an error, show another sweetalert popup. If there's no error, redirect to homepage.
All I did was prevent the default submission of the form and make an ajax request when "delete" is pressed (so result.isConfirmed
is true
). I've been trying to pass the CSRF token in data
and headers
too but I get this error all the time:
Uncaught (in promise) ReferenceError: bkF3gnRCrqiVjvKKLnP2kih90lYssXIINjIpLK8v is not defined
I'm not sure if that's doable and if so, how, but I would like to ask for some help. This is what I have so far:
*..prevent default and first sweetalert popup..*
.then((result) => {
if (result.isConfirmed) {
$.ajax({
type:'GET',
url:'{{ route("site.destroy", $record->id) }}',
headers: ('X-CSRF-Token', {{ csrf_token() }}),
error: ()=>{
Swal.fire(
'Something went wrong!',
'record was not deleted.',
'error')
}
*..end..*