Sweetalert 不会显示,但会更新
Posted
技术标签:
【中文标题】Sweetalert 不会显示,但会更新【英文标题】:Sweetalert won't show but it will update 【发布时间】:2021-09-26 08:26:41 【问题描述】:我想在单击设置按钮后显示一个sweetalert,但它不起作用。这是我的索引页面,设置按钮可以工作,但不会显示甜蜜警报。可能是什么问题,我该怎么办?
index.php
<form method='post' action='updataStatus.php'>
<button type='submit' name='but_update' class="inline-block float ml-2 mt-1 btn-group pull-right btn-danger btn-sm">SET</button><button type="submit" id="dataExport" name="dataExport" value="Export to excel" class="inline-block float ml-2 mt-1 btn-group pull-right btn-info btn-sm">Export</button>
<div class="table-responsive">
<br>
<tbody><table class="table table-hover table-bordered" id="sampleTable2">
<thead>
<tr>
<th><input type="checkbox" class="select-all checkbox" name="select-all" id="checkAll" /></th>
<th>Name</th>
<th>Scholarship Program</th>
<th>Course</th>
<th>Semester</th>
<th>Allowance</th>
</tr>
</thead>
<?php
require_once "connection.php";
$query = "SELECT * FROM allowance";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result) )
$id = $row['id'];
$Name = $row['Name'];
$Scholarship = $row['Scholarship'];
$Course = $row['Course'];
$Semester = $row['Semester'];
$statusAllowance = $row['statusAllowance'];
?>
<tr>
<!-- Checkbox -->
<td><input type='checkbox' name='update[]' value='<?= $id ?>' ></td>
<td><p name="Name"><?php echo $row['Name']; ?></p></td>
<td><p name="Scholarship"><?php echo $row['Scholarship'] ?></p></td>
<td><p name="Course"><?php echo $row['Course'] ?></p></td>
<td><p name="Semester"><?php echo $row['Semester'] ?></p></td>
<td><p name='statusAllowance_<?= $id ?>'><?php echo $row['statusAllowance'] ?></td>
</tr>
<
?php
?>
</table>
</tbody>
<?php
if(isset($_SESSION['success']) && $_SESSION['success'] !='')
?>
<script type="text/javascript">
swal(
title: "<?php echo $_SESSION['success']; ?>",
icon: "<?php echo $_SESSION['status_code']; ?>",
button: "yissh",
);
</script>
<?php
unset($_SESSION['success']);
?>
这是我在编辑部分的代码,它有效,只有警报不会出现。 更新数据状态.php
<?php
require_once "connection.php";
if(isset($_POST['but_update']))
if(isset($_POST['update']))
foreach($_POST['update'] as $id)
$statusAllowance = 'Received';
if($statusAllowance != '' )
$updateUser = "UPDATE allowance SET statusAllowance='".$statusAllowance."' WHERE id=".$id;
$query_run = mysqli_query($conn,$updateUser);
if($query_run)
$_SESSION['success'] = "YOUR DATA UPDATED";
header('Location: tracking.php');
else
$_SESSION['success'] = "YOUR DATA IS NOT UPDATED";
header('Location: tracking.php');
?>
【问题讨论】:
【参考方案1】:考虑到你还没有实现另一个函数来调用sweetalert;默认情况下,它应该是Swal.fire()
而不仅仅是swal()
https://sweetalert2.github.io/
【讨论】:
然后在 sweetalerts 网站上复制任何警报代码并在开发工具上复制粘贴,然后按 Enter。如果触发,则需要更多代码(例如必须检查是否包含session_start()
),但如果没有,则表示您尚未正确初始化 sweetalert(尝试在 <head></head>
中包含 cdn 脚本标签)以上是关于Sweetalert 不会显示,但会更新的主要内容,如果未能解决你的问题,请参考以下文章
Linux 图像不会显示在主根文件夹中,但会显示在子文件夹中
Rails 不会编译资产,但会在日志中显示编译,rake assets:precompile not generate files
Swift 4:UITableViewCell 在初始加载时不会显示数据,但会在第二次加载时加载