php - 看似异步的页面加载

标签 php javascript jquery

我不知道该怎么调用它,但是在 google plus 中,当您导航到不同的页面时,HTTP 地址会发生变化,但用户栏似乎保持静态并且不会重新加载。发生了什么,这是如何完成的?

我希望这是有道理的!谢谢!

最佳答案

AJAX(异步加载内容)

内容正在异步加载,地址栏中的 url 正在更改。

异步加载内容的基本示例:

$.ajax({
    url: 'http://www.example.net/load.html',
    dataType: 'html',
    success: function(data){
        // This will replace all content in the body tag with what has been retrieved
        $('body').html(data);
    }
});

参见 here对于 $.ajax() 文档。

在不重定向的情况下修改 URL

要通过重定向更改 url,您需要使用 HTML5 history API。以前在这里问过类似的问题,请参阅:

Modify the URL without reloading the page

提取的答案:

function processAjaxData(response, urlPath){
     document.getElementById("content").innerHTML = response.html;
     document.title = response.pageTitle;
     window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}

有关 HTML5 History API 的更多信息,请参阅 here .

关于php - 看似异步的页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16558626/

相关文章:

php - Laravel 4 - 使用 Eloquent 选择列表中 undefined variable

javascript - 表格行在一段时间不工作后变得淡出

javascript - 使用 Facebook API 发布到页面时添加定位

javascript - Angularjs 无法在 Nodejs Express 中工作

javascript - 按关闭按钮停止视频

javascript - 包含 FOREACH 可连接内容的表

javascript - 模态窗口不出现

php - 两个不寻常的 PHP 运算符一起用于获取图像像素颜色,请解释

javascript - 禁用多次点击 JavaScript

javascript - 向下滚动后导航淡入?