在執行AJAX成功後,我似乎無法重定向到新頁面(這是在jQuery Mobile的腳本中)。在下面的代碼中,如果我執行除重定向以外的其他功能,則sessionStorage會按預期設置。執行重定向時,sessionStorage代碼不會執行。建議?AJAX重定向成功覆蓋其他邏輯
$("#register").click(function() {
var formData = $("#registerUser").serialize();
$.ajax({
type: "POST",
url: "file.php",
//dataType:'json',
cache: false,
data: formData,
//success: onSuccess,
success: function (data) {
if (data.status == 'success') {
//execute some code here
var someValue = (data.id);
sessionStorage.setItem('someValue', someValue);
} else if (data.status == 'error') $("#notification").text(data.message);
},
complete: function() {
window.location.replace('newPage.html');
}
});
return false;
});
請注意,這是唯一的瀏覽器有問題。在Firefox中,一切都按預期工作。 – byoung 2012-08-02 19:46:08