解决:
不刷新改变网址地址
示例:
function onRequestSuccess() {
if (currentRequestUrl) {
inRequestState = true;
var currentMenuName = $(".submenu li.current").text().trim();
currentRequestUrl = currentRequestUrl.replace("&X-Requested-With=XMLHttpRequest", "");
History.pushState({ activeMenu: currentMenuName, title: "@ViewBag.Title", url: currentRequestUrl }, $("#wrap").find("title").text(), currentRequestUrl);
}
}
History.Adapter.bind(window, 'statechange', function () { // Note: We are using statechange instead of popstate
if (inRequestState) {
inRequestState = false;
return;
}
var state = History.getState(); // Note: We are using History.getState() instead of event.state
if (state) {
document.title = state.title;
var mn = state.data.activeMenu;
$.ajax({
type: "POST",
url: state.url,
success: function (data) {
$("#wrap").html(data);
switchMenu(mn);
},
failure: function (errMsg) {
$("#wrap").html("<p>服务器繁忙,请稍后再试.</p>");
console.log(errMsg);
}
});
}
});