php - Ajax 和 htaccess - 仅重定向内容 div,复制整个模板
问题描述
我想在我的页面中使用音频播放器,但是当页面刷新时播放器无法重新加载。所以,我将模板分为 3 个 div:页眉、内容和页脚,即播放器所在的位置。要重定向到另一个页面,我使用 ajax 仅刷新内容 div。同时,我使用 htaccess 将所有内容重定向到我的基本模板 index.php。我这样做是为了始终验证每个请求,在存在时显示请求的页面,或者在不存在时显示 404 页面。问题是当我重定向到任何页面时,例如“/about”。因为是htaccess,所以index.php 是要到内容div 的。我只想在 index.php 中加载我的基本模板一次。我的场景是否有解决方法。我不想使用来自客户端的任何信息,例如标头。只是出于安全原因。下面,有'
我的 index.php
<?php
//Creating base template...;
//Here, will be a URI validation
$uri = $_SERVER["REQUEST_URI"];
?>
<script>
$(document).on('click', "a", function(e){
$.ajax({
async: false,
url: document.location.pathname,
type: 'post',
success: function(ret) {
$("#content").html(ret);
}
});
return false;
});
</script>
<div id="header">
<a href="/home">Home</a>
<a href="/about">About</a>
</div>
<div id="content">
<h1>Content Here</h1>
</div>
<div id="footer">
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
我的 htaccess
RewriteEngine On
DirectoryIndex index.php
RewriteRule ^(.*)$ index.php [L]
我的 about.html 页面
</h1>About Page</h1>
解决方案
推荐阅读
- python - 更快的方法来获得列的平均值
- html - 在之间创建连接器盒子
- java - 有没有办法使 JPQL @Query 注释动态化?
- c++ - Inserting objects into binary search tree - C++
- javascript - 除了开发人员仪表板之外,还有哪些托管 chrome 扩展的替代方法
- php - 无法打开受密码保护的 zip 存档
- python - Python - 模糊字符串匹配 - TypeError:预期的字符串或类似字节的对象
- javascript - 为什么我的获取帖子不起作用它没有响应?
- c - 写长到linux char设备驱动程序?
- html - 修复了英雄顶部元素不接收指针事件的问题