网站包括我网站的页面/页面

时间:2010-03-17 21:30:23

标签: php html web

我的网站在index.html上用html + css。在我的index.html上我有这个div id“content”,你把主要内容放到页面上,并且在菜单栏上有一个链接src到page2.php。当你按下链接时,它会转到page2.php,但我希望它显示在< div“内容”。 在第2页我有你好这是一个测试,在回声..

我不想使用框架..我应该在index.php上拆分我的设计,然后在page2.php上包括top&页脚?还是有另一种方式

function test() {
var xhr = XMLHttpRequest();
xhr.onreadystatechange = function(){
   if(xhr.readystate==4 && xhr.status=200)
      document.getElementById('content').innerHTML = xhr.responseText;
};

xhr.open("GET", "start.php", false);
xhr.send(null);
}

<a href="start.php" onclick="test(); return false;">Hjem </a> | 

<div id="content" ></div>

3 个答案:

答案 0 :(得分:1)

  

使用AJAX向page2.php发布HTTP GET请求,并在div容器中显示结果(echo)。

有些如下,(在IE中不起作用)

<script>
function test(){
   var xhr = XMLHttpRequest();
   xhr.onreadystatechange = function(){
      if(xhr.readystate==4 && xhr.status=200)
         document.getElementById('content').innerHTML = xhr.responseText;
   };

   xhr.open("GET", "page2.php", false);
   xhr.send(null);
}

</script>
  Try AJAX online

答案 1 :(得分:0)

您可以使用XMLHttpRequest()而不仅仅"Hello this is a test",但您也可以将MySQL数据库中的任何数据设置为<div id="content"> innerHTML。

答案 2 :(得分:0)

就像您在问题中建议的那样,您应该考虑将index.html拆分为页眉和页脚。这将允许您的网站在没有JavaScript的情况下工作,您可能会发现它更容易或更有意义。

有一些非常好的教程,例如this one,但谷歌搜索php header footer会返回很多选项。

相关问题