javascript - 更新页面和网址而不重新加载

标签 javascript php html

如何在不重新加载网页的情况下更新网页和网址。我在SoundCloud看到了这个我想在我自己的项目中使用它。

这是我想要的想法:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="./js/jquery.min.js"></script>
</head>

<?php
$url = $_SERVER['REQUEST_URI'];

if (url == /login){
    include 'php/login.php'; 
    echo"<script>
        $(document).ready(function() {'
        history.pushState(null, null, '/login')
        });
        </script>"
}

if (url == /home){
    include 'php/home.php'
    echo"<script>
        $(document).ready(function() {'
        history.pushState(null, null, '/home')
        });
        </script>"
}
?>

</html>

问题是,例如,当我输入www.mydomain.com/home时,我得到(当然)一个服务器错误,表明该文件不存在。我该如何解决这个问题?

最佳答案

尝试在 JavaScript 中使用 window.location.hash=your_hash_string

关于javascript - 更新页面和网址而不重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22489865/

相关文章:

javascript - 创建最大体积的内切 3D 框,适合点数组

php - 无法在 php 中包含文件

php - session ID : Why does it need to be updated?

html - 带有折叠菜单栏的响应式导航菜单

mysql - 如何将数据从数据库传递到 Google Chart

javascript - 从 Google Chrome 浏览器控制台使用所有请求立即回答 Quora 上的问题

javascript - 使用 socket node.js 检测用户切换页面

javascript - 在 Javascript 中使用 'enum' 类型而不是字符串有什么意义吗?

php - 基于单字段的Mysql交集

html - 为什么 HTML5 中的导航栏做成列表?