PHP避免创建多个页面

时间:2016-10-23 06:01:28

标签: php jquery html ajax

我是第三年的IT学生我的一个模块是网页设计,所以我对这个概念很新,在我的任务中我需要创建一个预订系统。

我创建了这样的后端仪表板,这让我想到了我的问题。:

enter image description here

在图片的左侧垂直导航栏上,您可以看到用户有许多选项,例如查看预订添加新车

我的问题

而不是必须创建多个页面,例如makereservation.phpaddcars.php,这些页面都是查询数据库以显示结果的真正功能,

我想知道 是否只能保留这一页(仪表板)并在用户点击相应链接时调用,附加功能,在内容部分内 - 从而避免创建不必要的额外页面。

希望这有意义,如果您需要任何进一步的信息,请随时询问

1 个答案:

答案 0 :(得分:1)

query_to_db.php 是唯一一个对DB进行查询并返回HTML结果的页面

<ul>
<!--each link below has onclick='searcQuery("REQUEST_TYPE_HERE")'
 witch will make XHR request with GET method-->
<li><a href='#' onclick='searcQuery("makereservation")'>makereservation</a></li>
<li><a href='#' onclick='searcQuery("addcars")'>addcars</a></li>
</ul>
<div id='book-body'></div>
<script>
function searcQuery(typ){
    var xmlhttp = new XMLHttpRequest();

  xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      //print result to the div #book-body
      document.getElementById("book-body").innerHTML = this.responseText;
    }
  };
  xmlhttp.open("GET", "query_to_db.php", true);
  xmlhttp.send("&type="+typ);   
}
</script>

和你的html页面

{{1}}
相关问题