3
我有一个页面,我已经实现了一个长查询功能来检查记录的时间戳,所以它会在数据被编辑时更新。在JS中停止长查询功能
<script type="text/javascript">
var poll_url = 'http://mysite.com/poll/;
var my_ts = <?php $_SESSION['template_timestamp']; ?>;
(function poll(){
$.ajax({
url: poll_url,
type: 'post',
success: function(data){
if ((data.ts > 0) {
// check if expired
if (data.ts > my_ts) {
// it has expired, so reload the page
$("#dialog-message").html('Record has been edited.');
// show popup
$("#dialog-message").dialog({
modal: true,
buttons: {
Reload: function() {
$(this).dialog("close");
$('#pleaseWait').show();
window.location.href = '/records/overview';
}
}
});
}
} else {
// is still null
console.log('error');
}
},
dataType: "json",
complete: poll, timeout: 30000
});
})();
</script>
我的问题是,还有另一个作用,其调用JS Ajax调用,这被称为当我想迫使长轮询功能停止。
有没有办法做到这一点?
以下SO问题可以提供答案... http://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery –
@StuartWakefield;谢谢你。没有找到该片段。如果您发表评论作为答案,我会接受它。 – Rooneyl