【发布时间】:2017-11-12 00:38:22
【问题描述】:
所以,我非常喜欢 php、ajax 和任何 javascript。我已经通过各种教程和陈腐的方法将这个网站放在一起,使事情顺利进行。但是,我遇到了两个围绕 URL 的问题。
我不知道如何使用后退按钮将某些内容正确绑定到点击帖子时发生的操作。
子网址直接指向帖子内容(single.php),而不是内容拉起的索引模板。
现在,这是我的代码。我敢肯定它有一百万个问题。
(function($) {
$(function($) {
$(".post-link").click(function loadContent(){
$(this).parent().addClass('fullscreen');
$('.close').toggleClass('closeactive').removeClass('close');
$(".back, .next").show();
$('body').addClass('noscroll');
});
$(document).ready(function(){
$.ajaxSetup({cache:false});
$(".post-link").click(function(e){
var post_link = $(this).attr("href");
$(this).siblings('#single-post-container').html("content loading");
$(this).siblings('#single-post-container').load(post_link);
window.history.pushState('object', 'New Title', post_link);
e.preventDefault();
window.onpopstate = function(event) {
$("#loading").show();
console.log("pathname: "+location.pathname);
loadContent(location.pathname);
$(this).parent().removeClass('fullscreen');
};
return false;
});
});
});
基本上,发生的事情是大量的 css 和 ajax 调用。我不完全确定我做对了,但它运行得很好。你可以在我的网站 www.andbloom.com 上看到它的实现。任何帮助将不胜感激!
【问题讨论】:
-
这是一个糟糕的网站!我希望我能提供帮助,也不是最适合 ajax 和 js 的。我不太喜欢 ajaxy 网站,但我真的很喜欢这个。当 Netflix 更改为 ajax 时,我讨厌它。对于历史记录,请使用 html5 历史记录 (css-tricks.com/using-the-html5-history-api)。您可能想在 codeable.io(示例)上雇用一名忍者,或者在 Twitter 上进行一些易货交易。真的很棒!
-
还可以在这里查看源代码和 .js,非常简单的版本(旧但仍然值得学习):view-source:demo.tutorialzine.com/2009/09/simple-ajax-website-jquery/…
-
只是为您的网站添加书签。我是漫威怪胎!非常棒。
-
哦,谢谢!我已经查看了很多不同的 ajax 加载内容示例,我的困难在于我有围绕 url 更改的操作。
标签: php jquery ajax wordpress url