I knew SweetAlert2 when I made login features with HTML, JS, PHP, and MySQL.
so I wanted to put the SweetAlert2 alert tab when users succeeded in login, like the code below.
// user succeeded to log in and session was issued
// ....
Swal.fire({
icon: 'success',
title: 'Welcome',
text: 'You have logged in.',
}).then(() => location.href = "../index.php");
But I encountered some errors like at the console in the developer tool in a web browser and that feature didn't work as I expected.
sweetalert2@9:1 SweetAlert2: Target parameter is not valid, defaulting to "body"
_ @ sweetalert2@9:1
we @ sweetalert2@9:1
_main @ sweetalert2@9:1
r @ sweetalert2@9:1
i @ sweetalert2@9:1
fire @ sweetalert2@9:1
(anonymous) @ loginProcess.php:6
sweetalert2@9:1 Uncaught TypeError: Cannot read properties of null (reading 'querySelector')
at Q (sweetalert2@9:1)
at yt (sweetalert2@9:1)
at we (sweetalert2@9:1)
at r._main (sweetalert2@9:1)
at new r (sweetalert2@9:1)
at i (sweetalert2@9:1)
at Function.fire (sweetalert2@9:1)
at loginProcess.php:6
Should I use the SweetAlert2 only when the user clicks some buttons? If not, I want how to use SweetAlert2 without users' event triggering. Please let me know about this.
Thank you.