dongzhi2014 2018-03-05 19:47
浏览 84

.load()不会在加载的HTML文件中执行JavaScript

My .load() doesn't execute JavaScript in loaded HTML file.

I already try the answers in anothers same thread but I can't solve my issue.

Here is my code :

index.php

<?php
    session_start();
    if(empty($_SESSION['username']))
    {
        $_SESSION = array();
        //setcookie('auth', 'nop^^' , time() - 3600, '/', $_SERVER["HTTP_HOST"], false, true);
        session_destroy();
        header('Location: ../../frontsite/index.php');
        exit();
    }

    function menu_mode($requestUri)
    {
        $user_type = $_SESSION['admin'];
        if ($user_type == $requestUri)
            echo 'class="menu_section show"';
        else {
            echo 'class="menu_section hidden"';
        }
    }
    switch ($_SESSION['admin']) {
      case "admin":

          $pages = array(
            'admin_tableau_bord'          => 'admin_tableau_bord',
            'admin_conseilleres_liste'  => 'admin_conseilleres_liste',
            'admin_conseilleres_gestion'=> 'admin_conseilleres_gestion',
            'admin_liste_clients'         => 'admin_liste_clients'
            );

          $page = isset($_GET['page']) ? $_GET['page'] : 'admin_tableau_bord';

          if(!array_key_exists($page, $pages)) {
            $page = 'admin_tableau_bord';
          }

          break;
      case "user":

          $pages = array(
            'cons_tableau_bord'         => 'cons_tableau_bord',
            'cons_planning'             => 'cons_planning',
            'cons_liste_clients'         => 'cons_liste_clients',
            'cons_gestion_clients'       => 'cons_gestion_clients'
            );

          $page = isset($_GET['page']) ? $_GET['page'] : 'cons_tableau_bord';

          if(!array_key_exists($page, $pages)) {
            $page = 'cons_tableau_bord';
          }

          break;
    }
    require_once('../../frontsite/pages/db_connect.php');
?>

<!DOCTYPE html>
<html lang="en">
<head>
     ALL META & LINKS
</head>
<body class="nav-md">
<div class="container body">

... blablabla ... 

           <?php
              // affichage des liens du menu
              $i="0";
              foreach($pages as $key => $value) {
                $en_cours = ($key == $page) ? ' id="en_cours"' : ''; // test page en cours
                    $href[$i] = ' href="#" data-target="'.$key.'"'.$en_cours;
                $i += 1;
              }
            ?>

            <h3>Administrateur</h3>
            <ul class="nav side-menu">
              <li><a class="dyn_link" <?php echo $href[0]; ?>><i class="fa fa-home"></i> Tableau de bord </a></li>
              <li><a><i class="fa fa-female"></i> Conseillères <span class="fa fa-chevron-down"></span></a>
                <ul class="nav child_menu">
                  <li><a class="dyn_link" <?php echo $href[1]; ?>>Liste</a></li>
                  <li><a class="dyn_link" <?php echo $href[2]; ?>>Gestion</a></li>
                </ul>
              </li>
              <li><a class="dyn_link" <?php echo $href[3]; ?>><i class="fa fa-list"></i> Liste clients </a></li>

... blablabla ... 

    <!-- page content -->
    <div class="right_col" id="content_include" role="main">
      <?php
        include("../production/pages/$page.inc.php");
      ?>
    </div>

... blablabla ... 

    <!-- Include jQuery + ALL OTHER SCRIPT  -->
    <script src="../production/lib/jquery.js"></script>

    <!-- Load content Scripts -->
    <script>
     $(document).ready(function(){
       // Set trigger and container variables
       var trigger = $('.dyn_link'),
           container = $('#content_include');

       // Fire on click
       $(document.body).on('click','.dyn_link', function(event){
         event.preventDefault();
         // Set $this for re-use. Set target from data attribute
         target = $(this).data('target');

         // Load target page into container
         container.load('./' + target + '.inc.php');

         // Stop normal link behavior
         return false;
       });

     });
   </script>

</body>
</html>

My incuded files just contain html code. I am sure i make mistake in my way to load the content included.

Sorry for the heavy block but you have all the infos to help me if possible. Thanks a lot.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法