通过后退/前进操作触发 Ajax 功能?
首先,我要感谢大家阅读本文并回答我的问题。迄今为止所提供的帮助是非常宝贵的,并且由于所提供的帮助,我成为了更好的程序员。
针对手头的问题。我担心这有点粗糙,但下面的脚本大部分都有效。
问题是,虽然存储了历史记录,但当用户后退或前进时,页面不会更改。您知道我可以做什么来修改它以便触发 go 函数吗?
$(document).ready(function(){
$("a").click(function() {
if (strpos($(this).attr('href'), 'mob.php') !== false) {
window.location = url($(this).attr('href'));
go(idToPath($(this).attr('href')));
return false;
}
});
});
function go(num) {
if (num != undefined) {
$.ajax({
url: "mob.php?p="+num+"&logo=0",
cache: false,
success: function(html){
$("#ajax").html(html);
}
});
}
}
$.history.init(function(u) {});
var page = 4;
var id = window.location.hash.substr(1);
if (id != '' && page != id) {
go(id);
}
Firstly I would just like to thank everyone for reading this and answering my questions. The help given to date has been invaluable and I a better programmer thanks to the help I have been given.
To the problem at hand. I fear it is a little rough but the script below for the most part works.
The problem is that while the history is stored, when a user goes back or forward the page doesn't change. Do you have any idea what I can do to modify this so the go function is triggered?
$(document).ready(function(){
$("a").click(function() {
if (strpos($(this).attr('href'), 'mob.php') !== false) {
window.location = url($(this).attr('href'));
go(idToPath($(this).attr('href')));
return false;
}
});
});
function go(num) {
if (num != undefined) {
$.ajax({
url: "mob.php?p="+num+"&logo=0",
cache: false,
success: function(html){
$("#ajax").html(html);
}
});
}
}
$.history.init(function(u) {});
var page = 4;
var id = window.location.hash.substr(1);
if (id != '' && page != id) {
go(id);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有这样的活动。
但是你可以使用一些历史记录插件,看看它是如何完成的:
http://www.mikage.to/jquery/jquery_history.html
There isn't such event.
But you could use some history plugin, on see, how its done there:
http://www.mikage.to/jquery/jquery_history.html
好吧,我不确定这个问题有什么固定的解决方案。
但我为此想出了一个临时解决方案。
$_SESSION['page'][] = "book.php?cat=1"
这不是一个很好的答案,但这应该给你一个粗略的想法。 :)
Well, I am not sure of any fixed solution to this problem.
But I came up with a temporary solution for this.
$_SESSION['page'][] = "book.php?cat=1"
This is not much of a answer, but this should give you a rough idea. :)
将 ajax 添加到浏览器状态组合中会导致许多复杂的问题,如下所述:
如何在 URL 中显示 Ajax 请求?
< href="http://www.balupton.com/projects/jquery-ajaxy" rel="nofollow noreferrer">jQuery Ajaxy 项目是使用 ajax 和浏览器状态的一个很好的开始。
Adding ajax to the mix of browser-state causes a lot of compicated issues as documented here:
How to show Ajax requests in URL?
The jQuery Ajaxy project is a great start with using ajax and browser states.