Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery没有';t使用php include运行_Javascript_Php_Jquery_Html_Twitter Bootstrap - Fatal编程技术网

Javascript jQuery没有';t使用php include运行

Javascript jQuery没有';t使用php include运行,javascript,php,jquery,html,twitter-bootstrap,Javascript,Php,Jquery,Html,Twitter Bootstrap,当我包含文件header.php时,我遇到了index.php中jQuery没有运行的问题。导航侧边栏包括在内,但当我按下V形按钮时,什么也没发生?只有当我直接包含header\u user.php而不检查header.php中的UserType时,它才起作用。我不能直接包含header\u user.php,因为我需要根据UserType显示页面。在此代码中,假设当前的用户类型是用户。请帮忙。我不知道是什么问题 index.php <?php require_once 'sess

当我包含文件
header.php
时,我遇到了
index.php
中jQuery没有运行的问题。导航侧边栏包括在内,但当我按下V形按钮时,什么也没发生?只有当我直接包含
header\u user.php
而不检查
header.php
中的
UserType
时,它才起作用。我不能直接包含
header\u user.php
,因为我需要根据
UserType
显示页面。在此代码中,假设当前的
用户类型
用户
。请帮忙。我不知道是什么问题

index.php

<?php
    require_once 'session.php';
    require_once 'connection.php';
?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Nav Sidebar</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="bootstrap/css/dashboard.css" rel="stylesheet">

    <script>
    var change = true;
    $(document).ready(function () {
        $('[data-toggle=offcanvas]').click(function () {
            $('.row-offcanvas').toggleClass('active');
        });
    });

    function toggle_caret() {
        $("#caret1").toggleClass("glyphicon-chevron-down", change);
        $("#caret1").toggleClass("glyphicon-chevron-left", !change);
        change = !change
    }
    </script>
    </head>

    <body>
    <?php include 'header/header.php'; ?>
    <script src="jquery-1.11.1.min.js"></script> 
    <script src="bootstrap.min.js"></script>

    </body>
    </html>
<?php

    $UType = $_SESSION['UserType'];

    $tsql = "SELECT * FROM [dbo].[LOGIN] WHERE UserType='$UType'";
    $result = sqlsrv_query( $conn, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    while($row=sqlsrv_fetch_array($result))
    {
        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
    }
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li class="active"><a href="#"><span class="glyphicon glyphicon-dashboard"></span>&nbsp;&nbsp;Dashboard<span class="sr-only">(current)</span></a>
                </li>
                <li onclick="toggle_caret()"><a href="#" data-toggle="collapse" data-target="#sub1"><span class="glyphicon glyphicon-list-alt"></span>&nbsp;&nbsp;Requisition<small><span style="float:right" id="caret1" class="glyphicon glyphicon-chevron-down"></span></small></a>
                </li>
                <ul class="nav collapse" id="sub1">
                    <li><a href="#"><span class="glyphicon glyphicon-file"></span>&nbsp;&nbsp;Form</a>
                    </li>
                    <li class="nav-divider"></li>
                    <li><a href="#">Status</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;Approved</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;Rejected</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-refresh"></span>&nbsp;&nbsp;In Process</a>
                    </li>
                </ul>
            </ul>
            <ul class="nav nav-sidebar">
                <li class="nav-divider"></li>
                <li><a href="#"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;Search</a>
                </li>
            </ul>
        </div>
<?php

    $UType = $_SESSION['UserType'];

        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
?>

导航侧栏
var变化=真;
$(文档).ready(函数(){
$(“[data toggle=offcanvas]”)。单击(函数(){
$('.row offcanvas').toggleClass('active');
});
});
函数切换_插入符号(){
$(“#caret1”)。切换类别(“字形图标V形向下”,更改);
$(“#caret1”).toggleClass(“glyphicon雪佛龙左”!更改);
改变=!改变
}
header.php

<?php
    require_once 'session.php';
    require_once 'connection.php';
?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Nav Sidebar</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="bootstrap/css/dashboard.css" rel="stylesheet">

    <script>
    var change = true;
    $(document).ready(function () {
        $('[data-toggle=offcanvas]').click(function () {
            $('.row-offcanvas').toggleClass('active');
        });
    });

    function toggle_caret() {
        $("#caret1").toggleClass("glyphicon-chevron-down", change);
        $("#caret1").toggleClass("glyphicon-chevron-left", !change);
        change = !change
    }
    </script>
    </head>

    <body>
    <?php include 'header/header.php'; ?>
    <script src="jquery-1.11.1.min.js"></script> 
    <script src="bootstrap.min.js"></script>

    </body>
    </html>
<?php

    $UType = $_SESSION['UserType'];

    $tsql = "SELECT * FROM [dbo].[LOGIN] WHERE UserType='$UType'";
    $result = sqlsrv_query( $conn, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    while($row=sqlsrv_fetch_array($result))
    {
        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
    }
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li class="active"><a href="#"><span class="glyphicon glyphicon-dashboard"></span>&nbsp;&nbsp;Dashboard<span class="sr-only">(current)</span></a>
                </li>
                <li onclick="toggle_caret()"><a href="#" data-toggle="collapse" data-target="#sub1"><span class="glyphicon glyphicon-list-alt"></span>&nbsp;&nbsp;Requisition<small><span style="float:right" id="caret1" class="glyphicon glyphicon-chevron-down"></span></small></a>
                </li>
                <ul class="nav collapse" id="sub1">
                    <li><a href="#"><span class="glyphicon glyphicon-file"></span>&nbsp;&nbsp;Form</a>
                    </li>
                    <li class="nav-divider"></li>
                    <li><a href="#">Status</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;Approved</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;Rejected</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-refresh"></span>&nbsp;&nbsp;In Process</a>
                    </li>
                </ul>
            </ul>
            <ul class="nav nav-sidebar">
                <li class="nav-divider"></li>
                <li><a href="#"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;Search</a>
                </li>
            </ul>
        </div>
<?php

    $UType = $_SESSION['UserType'];

        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
?>

header\u user.php

<?php
    require_once 'session.php';
    require_once 'connection.php';
?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Nav Sidebar</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="bootstrap/css/dashboard.css" rel="stylesheet">

    <script>
    var change = true;
    $(document).ready(function () {
        $('[data-toggle=offcanvas]').click(function () {
            $('.row-offcanvas').toggleClass('active');
        });
    });

    function toggle_caret() {
        $("#caret1").toggleClass("glyphicon-chevron-down", change);
        $("#caret1").toggleClass("glyphicon-chevron-left", !change);
        change = !change
    }
    </script>
    </head>

    <body>
    <?php include 'header/header.php'; ?>
    <script src="jquery-1.11.1.min.js"></script> 
    <script src="bootstrap.min.js"></script>

    </body>
    </html>
<?php

    $UType = $_SESSION['UserType'];

    $tsql = "SELECT * FROM [dbo].[LOGIN] WHERE UserType='$UType'";
    $result = sqlsrv_query( $conn, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    while($row=sqlsrv_fetch_array($result))
    {
        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
    }
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li class="active"><a href="#"><span class="glyphicon glyphicon-dashboard"></span>&nbsp;&nbsp;Dashboard<span class="sr-only">(current)</span></a>
                </li>
                <li onclick="toggle_caret()"><a href="#" data-toggle="collapse" data-target="#sub1"><span class="glyphicon glyphicon-list-alt"></span>&nbsp;&nbsp;Requisition<small><span style="float:right" id="caret1" class="glyphicon glyphicon-chevron-down"></span></small></a>
                </li>
                <ul class="nav collapse" id="sub1">
                    <li><a href="#"><span class="glyphicon glyphicon-file"></span>&nbsp;&nbsp;Form</a>
                    </li>
                    <li class="nav-divider"></li>
                    <li><a href="#">Status</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;Approved</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;Rejected</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-refresh"></span>&nbsp;&nbsp;In Process</a>
                    </li>
                </ul>
            </ul>
            <ul class="nav nav-sidebar">
                <li class="nav-divider"></li>
                <li><a href="#"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;Search</a>
                </li>
            </ul>
        </div>
<?php

    $UType = $_SESSION['UserType'];

        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
?>

编辑

我发现在如下更改查询之后,jQuery工作了。有人能解释为什么会这样吗

header.php

<?php
    require_once 'session.php';
    require_once 'connection.php';
?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Nav Sidebar</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="bootstrap/css/dashboard.css" rel="stylesheet">

    <script>
    var change = true;
    $(document).ready(function () {
        $('[data-toggle=offcanvas]').click(function () {
            $('.row-offcanvas').toggleClass('active');
        });
    });

    function toggle_caret() {
        $("#caret1").toggleClass("glyphicon-chevron-down", change);
        $("#caret1").toggleClass("glyphicon-chevron-left", !change);
        change = !change
    }
    </script>
    </head>

    <body>
    <?php include 'header/header.php'; ?>
    <script src="jquery-1.11.1.min.js"></script> 
    <script src="bootstrap.min.js"></script>

    </body>
    </html>
<?php

    $UType = $_SESSION['UserType'];

    $tsql = "SELECT * FROM [dbo].[LOGIN] WHERE UserType='$UType'";
    $result = sqlsrv_query( $conn, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    while($row=sqlsrv_fetch_array($result))
    {
        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
    }
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li class="active"><a href="#"><span class="glyphicon glyphicon-dashboard"></span>&nbsp;&nbsp;Dashboard<span class="sr-only">(current)</span></a>
                </li>
                <li onclick="toggle_caret()"><a href="#" data-toggle="collapse" data-target="#sub1"><span class="glyphicon glyphicon-list-alt"></span>&nbsp;&nbsp;Requisition<small><span style="float:right" id="caret1" class="glyphicon glyphicon-chevron-down"></span></small></a>
                </li>
                <ul class="nav collapse" id="sub1">
                    <li><a href="#"><span class="glyphicon glyphicon-file"></span>&nbsp;&nbsp;Form</a>
                    </li>
                    <li class="nav-divider"></li>
                    <li><a href="#">Status</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;Approved</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;Rejected</a>
                    </li>
                    <li><a href="#"><span class="glyphicon glyphicon-refresh"></span>&nbsp;&nbsp;In Process</a>
                    </li>
                </ul>
            </ul>
            <ul class="nav nav-sidebar">
                <li class="nav-divider"></li>
                <li><a href="#"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;Search</a>
                </li>
            </ul>
        </div>
<?php

    $UType = $_SESSION['UserType'];

        if($UType == "USER")
        {
            include 'header_user.php';
        }
        else if ($UType == "SUPERIOR")
        {
            include 'header_superior.php';
        }
        else if ($UType == "ADMIN")
        {
            include 'header_admin.php';
        }
        else 
        die("Not a Valid User Type.");
?>

我刚刚收集了所有源代码,并在本地测试了您的HTML。我遇到一些错误,因此建议将代码更改为:

index.php(将JS代码移到jQuery和引导脚本标记下面)


您确定UserType会话变量设置正确,并且脚本不仅仅在header.php中调用die()时关闭吗?尝试用echo替换die(),看看会发生什么。@Paul是的。会议没有问题。我尝试直接将文件包括到
header.php
中,而不是
header\u user.php
中,jQuery成功了。所以会话没有问题。是的,但这不能测试我的要求。。。为了便于讨论,请尝试用echo替换die(),或插入
$UType=“USER”紧跟在
$UType=$\u会话['UserType']之后@Paul我已经更新了。请看一看,这显然与您的数据库查询有关。它应该在做什么?在while()循环中有条件块,但从未引用$row。您只是检查是否返回了记录吗?我无法访问您的数据库或其他代码,所以我只是在暗中试探一下。同时,看看我在下面提交的一些建议。你有哪些错误?因为我没有得到任何:O,我的html在本地主机上运行良好,所以我添加了功能更改的描述。我所做的其他任何更改都只是为了与您的编程风格保持一致。祝你好运可以我之所以在页面末尾加载JS代码,是因为据我所知,它会加载得更快。但由于我只是一个初学者,谢谢你的建议:)真的,你只想在HTML之后加载外部脚本。您编写的代码依赖于jQuery,因此在库之前加载时会抛出一个错误。这很奇怪,因为即使在页面末尾加载了库,我也可以毫无错误地运行代码:\