由于我精心修改了一些代码,我的网站运行得更快了,但如果浏览器的后退/前进按钮能正常工作,我会很高兴。现在,使用下面的代码,浏览器地址栏永远不会改变。当有人单击“返回”时,它会将他们从应用程序中取出。
是否有任何简单的方法来改变它,以便浏览器的后退/前进按钮起作用?或者,如果有人能指出我正确的方向。谢谢你的帮助。
$(document).on("ready", function () {
//I want to load content into the '.page-content' class, with ajax
var ajax_loaded = (function (response) {
$(".page-content")
.html($(response).filter(".page-content"));
$(".page-content .ajax").on("click", ajax_load);
});
//the function below is called by links that are described
//with the class 'ajax', or are in the div 'menu'
var history = [];
var ajax_load = (function (e) {
e.preventDefault();
history.push(this);
var url = $(this).attr("href");
var method = $(this).attr("data-method");
$.ajax({
url: url,
type: method,
success: ajax_loaded
});
});
//monitor for clicks from menu div, or with
//the ajax class
//why the trigger?
$("#menu a").on("click", ajax_load);
$(".ajax").on("click", ajax_load);
$("#menu a.main").trigger("click");
});