【问题标题】:URI changes without reload?URI更改而不重新加载?
【发布时间】:2013-07-21 20:26:39
【问题描述】:
【问题讨论】:
标签:
jquery
ajax
themes
uri
tumblr
【解决方案1】:
他们使用这种代码:
$('a').click(function() {
link = $(this).attr('href')
history.pushState({}, '', link);
$('#content').load('/content.php?url='+link)
return false;
})
history pushstate function 允许您添加和修改浏览器历史记录条目。
【解决方案2】:
我们使用 Backbone + HTML5 pushState 来处理没有哈希的 URI 更改。之所以有效,是因为我们遵循 Tumblr 为所有博客构建其 URL 的方式。
我们使用 jQuery.load 来处理获取 html 并将其加载到页面中。
这段代码看起来有点像这样:
$container.load('http://blog.tumblr.com/post/123 #container', function() {
var $post = that.$('.overlay-container .post');
that.view = new App.PostViewFactory.createView($post);
that.view.on('close', function() {
window.history.back();
});
});
希望对您有所帮助。