I am trying to echo Notify.js notification script after the PHP code has been executed, however, it is not working for some reason.
if (!mysqli_stmt_prepare($stmt, $query)) {
echo alert('Sorry, something went wrong.');
exit();
}else{
mysqli_stmt_bind_param($stmt, 's', $cat_name);
mysqli_stmt_execute($stmt);
echo "<script>window.open('index.php?add_category','_self')</script>";
// notify.js notification
echo '<script>$.notify("Notification text...", "success");</script>';
}
As you can see in the code, after the statement has been executed, the page reloads and thats the moment when I want to get the notification. Could someone tell me please, me what I am doing wrong? Thanks.
You are trying to perform an action after the page is lost.
When you run window.open
with _self
as the target, you can fairly safely assume that no other JS on the current page will run.
What you will want instead, is checking on the index.php
page for the add_category
$_POST
key, and trigger your notification at that time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.