如何使用 PHP 将数据插入 MySQL 表后显示 jquery msgBox


How to display jquery msgBox after data is inserted to MySQL table using PHP

我想在数据已经插入到 MySQl 表中时显示一个消息框。我的代码如下:

 if($insert_query)
    {  
    <script type='text/javascript'> 
    $.msgBox('Data Added');
    window.location = 'bentry.php'; 
    </script> 
    }

但不显示警报。如何解决这个问题。

试试这个:

echo "<script type='text/javascript'> 
    $.msgBox('Data Added');
    window.location = 'bentry.php'; 
    </script> "

if($insert_query)
    {  ?>
    <script type='text/javascript'> 
    $.msgBox('Data Added');
    window.location = 'bentry.php'; 
    </script> 
  <?php  } ?>

原因是

 window.location = 'bentry.php'; 

$.msgBox('Data Added');已加载,但重定向脚本已导航到另一个页面。

if($insert_query)
{  
<script type='text/javascript'> 
$.msgBox('Data Added');
setTimeout(function(){window.location = 'bentry.php';},1000); 
</script> 
}