0
我有一个重定向到页面的按钮。我想要重定向的页面的PHP脚本需要几分钟的时间。在等待PHP脚本时,我希望setInterval调度程序使用jQ AJAX刷新内容,但似乎并未在重定向加载时执行。有任何想法吗?
代码:
heartbeatInterval = 10000;
$(document).ready(
function() {
console.log('Document got ready.')
setInterval(function() {
heartbeat();
}, heartbeatInterval);
});
$('#button').click(function() {
window.location.href = '/...';
});
function heartbeat() {
console.log('Heartbeat triggers.');
$.ajax({
url : action_heartbeat,
type : 'POST',
data : 'test',
success : function(response) {
$('#status').css('color', 'green').html($('#status').html() + '<br>Connected: ' + response);
console.log('Heartbeat finishes.');
},
error : function(xhr, message) {
$('#status').css('color', 'red').html($('#status').html() + '<br>Connection lost: ' + message);
}
});
}
我们有很多想法。你想与我们分享你的代码,以便我们可以帮助你吗? –
请给我们一些代码。另外我要调查的第一件事就是为什么一个页面需要几分钟的时间才能运行......并且,我想你的代码甚至会向同一个脚本发送几个连续的请求,使其运行得更慢...... –
长的PHP脚本是很好,它产生了很多东西,一些分钟是一个不错的表现。我称之为Ajax请求的PHP脚本并不相同。那个需要大约100ms。 – Aich