【发布时间】:2014-06-26 09:20:22
【问题描述】:
我有一个使用 setInterval() 的简单队列系统,我使用 jquery ajax 检查后端的队列。当满足某些条件时,我想重定向到该人可以继续该过程的页面。
在 Firefox 上,我得到了预期的重定向,但在 IE 和 Chrome 上却没有。 IE 简单地给出“无法显示此页面”错误,Chrome 给出“此网页存在重定向循环”错误。
有什么想法吗?
这是我的代码:
$(document).ready(function () {
StartTheTimer();
function StartTheTimer(e) {
var sec = parseInt($("#RefreshSeconds").val()) + 1;
var timer = setInterval(function () {
$('#spanQueueCountdown').text(--sec);
if (sec == 1) {
$('#spanSeconds').text('second');
}
else {
$('#spanSeconds').text('seconds');
}
if (sec == 0) {
clearInterval(timer);
$.ajax({
type: "POST",
url: "/Purchase/CheckQueue",
data: {
applicationSessionId: $("#ApplicationSessionId").val(),
eventId: $("#EventId").val(),
ordernumber: $("#OrderNumber").val()
},
cache: false,
dataType: "json",
success: function (result, textStatus, jqXHR) {
if (result.success && jqXHR.status == 200) {
if (!result.redirect) {
$("#spanQueueNumber").text(result.positionInQueue);
StartTheTimer();
}
else {
window.location.replace(result.redirecturl);
}
}
else {
console.log('Checking the queue failed.')
window.location.href = "/";
}
},
error: function () {
console.log('Error in checking queue.')
window.location.href = "/";
}
});
}
if ($('#spanQueueNumber').text() == 0) {
clearInterval(timer);
$('#spanQueueCountdown').text(0);
}
}, 1000);
}
});
【问题讨论】:
标签: jquery ajax asp.net-mvc redirect