从另一个PHP页面加载内容到索引PHP页面

时间:2018-09-14 10:21:23

标签: javascript php jquery html

我在 index.php 上有一个#container1 div。 我正在尝试从 page1.php 中加载#container2 div的内容到#container1 中。 我不知道为什么这行不通。

我的文件层次结构是这样的:

Project

 -Js
  --myJs

 -index.php
 -page1.php

index.php:

<!doctype html>
<html dir="rtl">
    <head>
    <base href="..\project\">
        <title></title>
        <link href="https://fonts.googleapis.com/css?family=Amatic+SC|Assistant" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css"  />
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
        <script src="js/myJs.js"></script>
    </head>
    <body>
<div id="container">
</div>
</body>
</html>

page1.php

<!doctype html>

    <head>
    <base href="..\project\">
        <title></title>
        <link href="https://fonts.googleapis.com/css?family=Amatic+SC|Assistant" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css"  />
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
        <script src="js/myJs.js"></script>
    </head>
    <body>
        <div id="container2">
            <div id="hello" style="height:100px; width:100px; background-color:blue;">
                <p>hello<p>
            </div>
        </div>
    </body>
</html>

myJs.js:

$(document).ready(function(){ 
    $("#container").load("../page1.php #container2> *");
});

索引否则显示就好。当我手动将div #hello 放入#container1 时,它可以完美显示。 page1 也显示得很好。

调试并没有告诉我太多。该代码已成功进入该函数,但 hello 却没有显示。 控制台为空。

0 个答案:

没有答案