简体   繁体   English

Bootstrap下拉列表在PHP死后停止工作

[英]Bootstrap dropdown stop working after php die

Hi i have a script in which there are bootstrap dropdowns. 嗨,我有一个脚本,其中有引导程序下拉列表。 The code for it is as follows:- 它的代码如下:-

<ul class="nav navbar-nav navbar-right">
    <li class="dropdown dropdown-user" style="font-size:15px;">
        <a class="dropdown-toggle" data-toggle="dropdown">
        <i class="icon-user"></i>&nbsp; <span><?php echo $name; ?></span>&nbsp;&nbsp;<i class="caret"></i></a>

        <ul class="dropdown-menu dropdown-menu-right width-220">
            <li><a href="changepassword.php"><i class="icon-lock2"></i> Change Password</a></li>
            <li><a href="../logout.php"><i class="icon-switch2"></i> Logout</a></li>
        </ul>
    </li>
</ul>

Now i run a php script after a form is submitted in which i am checking whether a table is there in the database or not. 现在,我在提交表单后运行php脚本,在其中检查数据库中是否有表。 If it is there it fethces it and if it is not there php script dies. 如果有的话,如果没有,php脚本就会死掉。 The code for it is below:- 它的代码如下:

<?php
  if(isset($_POST['submit']))
   {
       $sql="SELECT * FROM table1";
       $results = $con->query($sql);
       if ($results === FALSE) {
       echo "<script> noty({text: 'No Data Found',layout: 'topRight',timeout: 3500,closeWith: ['click', 'hover'],type: 'error'});</script>";
       die();
      } else {
      ........
      }

Now whenever the php script dies the dropdowns stop working. 现在,只要php脚本消失,下拉列表就停止工作。

I am just starting to learn php so please let me know what I am doing wrong or if there is a better way of looking at this problem. 我刚刚开始学习php,所以请让我知道我做错了什么,或者是否有解决此问题的更好方法。 Any help is highly appreciated. 非常感谢您的帮助。

Check if you included bootstrap js file at the end of your page. 检查页面末尾是否包含bootstrap js文件。 So when PHP dies, The bootsrap will not be loaded to the page. 因此,当PHP死亡时,bootsrap将不会加载到页面中。 If its the reason change die with something else or move bootstrap js file to header. 如果原因更改了其他原因,或者将bootstrap js文件移至标头。

PS:Besides use die whenever something goes wrong is not the best idea to handle errors. PS:除了出错时,使用死法并不是处理错误的最佳方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM