0
我使用php,html和sweetalert2 java腳本函數向用戶顯示一些通知。我需要在將用戶重定向到同一(目標)頁面後顯示警報。這是我的代碼有如何在php中執行一些java腳本後重定向用戶
function delete_cat(){
include("include/db.php");
include("include/notification.php");
$delete_cat_id = $_GET['delete_cat'];
$delete_cat= $con->prepare("DELETE FROM main_cat WHERE cat_id='$delete_cat_id'");
if($delete_cat->execute()){
echo '<script type="text/javascript">
deleteMainCatSuccess();
</script>';
echo "<script>window.open('index.php?viewall_cat','_self')</script>";
}
else{
echo '<script type="text/javascript">
deleteMainCatError();
</script>';
}
}
這是通知Java腳本
<script type="text/javascript">
function deleteMainCatSuccess(){
swal({
title: "Success",
text: "Delete Main Category Success",
type: "success",
timer: 3000
},
function(){
//event to perform on click of ok button of sweetalert
});
}
</script>
這工作,但通知顯示小於1秒,重定向頁面後。我需要留出一些時間來顯示通知,然後將用戶重定向到我的目標頁面。我在選項中包含了timer: 3000
,但它似乎沒有什麼區別。
我能做些什麼來解決這個問題?
移動的'window.open'打電話到'swal'回調函數。 –
我可以在哪裏學習?你可以給參考:) –
你的代碼是非常危險的。您對SQL注入攻擊持開放態度......使用準備/參數化查詢完全避免此問題。您還正在對HTTP GET請求進行更改。這違反了各種標準,並且容易受到跨源攻擊。有一個'DELETE'動詞。如果您要刪除某些內容,請使用它。對於數據更新,酌情使用'POST'或'PUT'。 – Brad