我是新在ajax wordpress,我已经显示了与ajax的帖子,但现在我有问题,我想显示与ajax的前一篇文章,意味着我已经显示了与ajax的帖子,当用户点击一个帖子,它会显示,当点击浏览器后退按钮,然后以前的帖子没有show.Can任何人告诉我如何显示浏览器后退按钮以前的wordpress ajax帖子。下面是我使用的代码
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery(".ajaxclick").click(function() {
var post_id1 = $(this).parent("li").attr("id");
var pageurl = $(this).attr('href');
alert(pageurl);
var ajaxURL = '<?php echo get_admin_url(); ?>admin-ajax.php';
$.ajax({
url: ajaxURL,
type: 'POST',
beforeSend: function() {
$("#loading-animation").hide();
$("#ajaxloader").show();
},
complete: function() {
$("#loading-animation").show();
$("#ajaxloader").hide();
},
data: {
action: 'load-content',
post_id: post_id1
},
success: function(response) {
jQuery("#loading-animation").addClass('loadingstyle');
jQuery("#loading-animation").html(response);
return false;
}
});
});
});
</script>发布于 2013-04-15 12:49:40
使用散列#,
$(function(){
if(location.hash === 'somepage'){
//do ajax again automatically here
}
});并在成功时添加散列:
success: function(response) {
jQuery("#loading-animation").addClass('loadingstyle');
jQuery("#loading-animation").html(response, function(){
location.hash = 'somepage';//<<-- must be identic with loaded page and same with above
});祝好运!
发布于 2013-04-15 12:59:14
有一个jquery插件似乎可以有效地管理这一点
这个jQuery插件通过跨浏览器的HTML5 window.onhashchange事件实现了非常基本的可加书签的#散列历史。
http://benalman.com/projects/jquery-hashchange-plugin/ https://stackoverflow.com/a/173075/1061871
html5解决方案:https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate
发布于 2013-04-23 12:54:56
我已经解决了这个问题,现在ajax帖子可以很好地使用浏览器的后退按钮和前进按钮,这段代码是在ajax帖子加载ajax后使用的,然后这段代码将用于显示浏览器的后退按钮,下面是代码:
// Bind an event to window.onhashchange that, when the hash changes,
$(window).on('hashchange', function(){
//check if hash tag exists in the URL
if(window.location.hash) {
var ajaxURL1 = '<?php echo get_admin_url(); ?>admin-ajax.php';
//set the value as a variable, and remove the #
var post_id1= window.location.hash.substring(1);
$.ajax({
url: ajaxURL1,
type: 'POST',
cache:false,
data: {
action: 'load-content',
post_id: post_id1
},
success: function(response) {
jQuery("#loading-animation").addClass('loadingstyle');
jQuery("#loading-animation").html(response);
return false;
}
});
}
else
{
window.location="http://203.134.217.4/testingwp/";
}
});https://stackoverflow.com/questions/16007756
复制相似问题