微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sweetalert 不会显示,但会更新

如何解决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');
                                        }

                                    
                                }
                            }
                            
                        }
                      }

                ?>

解决方法

考虑到你还没有实现另一个调用sweetalert的函数;默认情况下,它应该是 Swal.fire({}) 而不仅仅是 swal({})

https://sweetalert2.github.io/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。