gpt4 book ai didi

php - 看似异步的页面加载

转载 作者:行者123 更新时间:2023-11-29 18:22:56 25 4
gpt4 key购买 nike

我不知道该怎么调用它,但是在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com