简体   繁体   English

历史Api

[英]History Api

$('#Head a').click(function()
{
    alert("");
    var link = $(this).attr('href');
    $.get(link, function(data) {
        $('#NavDetailContent').html(data);
        history.pushState(null, null, link);
        e.preventDefault();
    });
    return false;
});

$(window).bind("popstate", function() {
    $.get(document.location, function(data) {
        $('#NavDetailContent').html(data);
        alert("");
    });
});

I was tring out history api but i found the following. 我正在试用历史API,但是发现了以下内容。

  1. When i move from a ajax link to a non ajax link and i click back only the content that was got from ajax only showed up and not the full page. 当我从ajax链接移至非ajax链接时,我仅单击返回从ajax获取的内容,而不显示整个页面。 So why is this because of history api or what (this is all that show's up on back) 那为什么是因为历史API或其他原因(这就是背面所显示的一切) 在此处输入图片说明

  2. when i refresh the page the popstste event is fired. 当我刷新页面时,将触发popstste事件。 This time if i am on a non ajax page it fires a request and loads the content in a div . 这次,如果我在非ajax页面上,它将触发请求并将内容加载到div中。 I have taken care on my sever side to show up different pages for ajax and non ajax even when it's ajax request but it shows up non ajax page, only in this case all other times it works fine 我已经在服务器端小心了,即使当它是ajax请求时也显示ajax和non ajax的不同页面,但是它显示了非ajax页面,仅在这种情况下所有其他时间都可以正常工作

On this project https://github.com/defunkt/jquery-pjax there is used special HTTP header to prevent this. 在这个项目中https://github.com/defunkt/jquery-pjax有使用特殊的HTTP标头,以防止这一点。 They use the same way to generate content AJAX and NONAJAX, but if you use ajax, on server side, the content arround is not generated. 它们使用相同的方法来生成内容AJAX和NONAJAX,但如果你使用AJAX,在服务器端,以防万一不产生内容。 So when you go back, you send link to server without special HTTP header, so page is generated full with all countent arround. 所以,当你回去,你发链接到服务器,而无需特殊的HTTP标头,从而产生完全与所有countent角落找寻页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM