2016-06-01 65 views
0

我的header.php和footer.php文件没有被index.html文件抓取。我已经通过Stackoverflow进行了搜索,并且遵循了不同的变体,例如<?php include("header.php"); ?>$("#header").load("header.html");,但它仍然不起作用。我的代码如下,有人可以告诉我我做错了什么?html网页的页眉和页脚php调用不起作用

的header.php

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <title>aaaa</title> 
    <meta name="description" content="aaaa."> 
    <link rel='shortcut icon' href='myfavicon.ico' type='image/x-icon'/ > 

    <!-- Bootstrap --> 
    <link href="css/bootstrap.min.css" rel="stylesheet"> 

    <!-- Custom CSS --> 
    <link href="css/custom.css" rel="stylesheet"> 
    <!-- Custom Fonts --> 
    <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,700' rel='stylesheet' type='text/css'> 
    <!-- Font Awesome --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css"> 

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 
     <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <![endif]--> 
    </head> 

<header> 
     <!-- HEADER --> 
    <nav class="navbar navbar-default"> 
     <div class="container-fluid"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse"> 
        <span class="sr-only">Toggle navigation</span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 
     <a class="navbar-brand" href="index.html"> 
      <img alt="aaaa" src="images/aa.png" height="30px"> 
     </a> 
     </div>  
     </div><!--END CONTAINER FLUID--> 
    </nav> 

的Index.html

<?php include("header.php"); ?> 
<div class="container-fluid"> 
      <div class="row feature"> 
       <img src="images/Homepage%20Banner.jpg" class="img-responsive" alt="aaaa"> 
       <div class="feature-text col-xs-12 col-md-8 col-lg-6 col-md-offset-2 col-lg-offset-3"> 
        <p>aaaaa</p> 
       </div><!--END FEATURE TXT--> 
      </div><!--END ROW FEATURES--> 
+0

您在控制台中看到的错误是什么? 'header.php'与index所在的位置相同吗?将'index.html'更改为'index.php'。并且,它不是'$(“#header”)。load(“header.html”);',它应该是'$(“#header”)。load(“header.php”);' – Thamilan

回答

0

,而不是index.html的变化的index.php。 通过只使用php文件我们可以包含其他的php文件。

1

PHP代码位于文件扩展名为.php。 而在Header.php中,如果您没有php代码,那么只需将它们写入.HTML扩展名即Header.html 因此,请将index.html重命名为index.php

0

您不能在.html文件中运行PHP,因为除非您告诉它,否则服务器不会将其识别为有效的PHP扩展。

这里<?php include("header.php") ?>是HTML文件中的php代码。

您需要将index.html更改为index.php