我可以将数据设置到 History.js 的 State.data 中,如下所示:
var pushStateData = {};
function RetrieveSearchResults(type, url, searchData) {//, showResetButton,
controlToFocus, navDirection) {
pushStateData = {
SearchType : type,
SearchData : searchData,
};
RetrievePageResults(true, url, pushStateData);
}
function RetrievePageResults(pushNewUrl, url, pushStateData) {
navigationInProgress = true;
if (pushNewUrl) {
if (window.History) {
window.History.pushState(pushStateData, null, url);
}
$.get(url, pushStateData.SearchData, function (reply) {
$("#search-results").html(reply);
navigationInProgress = false;
});
}
如果我在 window.History.pushState 语句上设置断点,在 Chrome 中,我可以清楚地看到 pushStateData 具有所需的值。
但是,当我尝试检索数据时:
$(window).bind("statechange", function (e) {
if (!navigationInProgress) {
var State = window.History.getState();
if (window.console && window.console.log) {
console.log("popstate", State, window.location.href);
}
RetrievePageResults(false, State.cleanUrl, State.data);
}
});
当我在 RetrievePageResults 语句上设置断点时,State.data 对象不再具有我设置的任何值。State.data 已定义,并且不为空,但它是一个没有任何明显值的空对象。
谢谢,斯科特