2016-06-01 64 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