簡體   English   中英

如何使用 PHP 正確回顯 Notify.js 通知?

[英]How to correctly echo Notify.js notification using PHP?

我試圖在 PHP 代碼執行后回顯 Notify.js 通知腳本,但是,由於某種原因它不起作用。

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>';
}

正如您在代碼中看到的那樣,在執行語句后,頁面會重新加載,這就是我想要獲取通知的時刻。 有人可以告訴我,我做錯了什么嗎? 謝謝。

您正在嘗試在頁面丟失后執行操作。

當您以_self作為目標運行window.open時,您可以相當安全地假設當前頁面上沒有其他 JS 將運行。

相反,您想要的是在index.php頁面上檢查add_category $_POST鍵,並在那時觸發您的通知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM