如何在一些微粒时间后在后台运行ajax调用? [英] How to run ajax call in background after some particulate time?

查看:74
本文介绍了如何在一些微粒时间后在后台运行ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在一些特定时间之后显示警告消息为你想要继续吗?
如果用户说是,那么ajax调用必须在后台运行,否则取消ajax调用。
那么请告诉我如何在ajax呼叫响应中设置时间条件?

I want to show alert message after some perticulate time as 'Do you want continue?' If user say yes then ajax call must be run in background otherwise cancel the ajax call. So please tell me how I can place time condition in ajax call response?

推荐答案

我从你的问题中理解了什么在您询问用户是否要继续之前,是否会进行ajax调用?

What i understood from your question is that the ajax call will be made before you ask the user "whether you would like to continue or not" correct?

我相信你想确保用户想要等待ajax调用需要很长时间吗?

And i believe you wanted to make sure the user want to wait if the ajax call is taking long time?

如果是这种情况你只需在用户上设置一个标志,按否并中止ajax调用

if this is the case you just set a flag on user press "no" and just abort the ajax call

// Assign handlers immediately after making the request,
// and remember the jqXHR object for this request
var jqxhr = $.ajax( "example.php" )
  .done(function() {
    alert( "success" );
  })
  .fail(function() {
    alert( "error" );
  })
});

//when user pressed no call the below function if the ajax is not completed
jqxhr.abort()

这篇关于如何在一些微粒时间后在后台运行ajax调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆