Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 五秒钟后重试Ajax调用_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 五秒钟后重试Ajax调用

Javascript 五秒钟后重试Ajax调用,javascript,jquery,ajax,Javascript,Jquery,Ajax,在这段代码中,$.ajax(this)错误地根据需要进行了五次ajax调用,但每次请求之间需要五秒钟的延迟。请帮忙 $.ajax({ type: "POST", data: JSON.stringify(download), contentType: "application/json", url: '', retryCount: 1, retryLimit: 5, success: function(data) { $.ajax({ type:

在这段代码中,$.ajax(this)错误地根据需要进行了五次ajax调用,但每次请求之间需要五秒钟的延迟。请帮忙

$.ajax({
  type: "POST",
  data: JSON.stringify(download),
  contentType: "application/json",
  url: '',
  retryCount: 1,
  retryLimit: 5,
  success: function(data) {
    $.ajax({
      type: "GET",
      url: '',
    })
        .success(function(data) {

    })
        .error(function(data) {

    })
  },
 //It has to go into error
  error : function(xhr, textStatus, errorThrown ) {
    this.retryCount++;
    if (this.retryCount <= this.retryLimit) {
      //try again
      $.ajax(this);
      return;
    } else {
      //user comes here After trying in the if loop for 5 times, with each request having five seconds delay. I am not able to keep delay between each request
    }
    return;
  }

});
$.ajax({
类型:“POST”,
数据:JSON.stringify(下载),
contentType:“应用程序/json”,
url:“”,
retryCount:1,
报复:5,
成功:功能(数据){
$.ajax({
键入:“获取”,
url:“”,
})
.成功(功能(数据){
})
.错误(函数(数据){
})
},
//它必须出错
错误:函数(xhr、textStatus、errorshown){
这个.retryCount++;
如果(this.retryCount尝试以下方法:

error : function(xhr, textStatus, errorThrown ) {
    this.retryCount++;
    if (this.retryCount <= this.retryLimit) {
      //try again
      var ajaxObject = this;
      window.setTimeout(function(){
          $.ajax(ajaxObject);
      },5000);

      return;
    } else {
      //user comes here After trying in the if loop for 5 times, with each request having five seconds delay. I am not able to keep delay between each request
    }
    return;
  }
error:函数(xhr、textStatus、errorshown){
这个.retryCount++;

如果(this.retryCount尝试像这样包装Ajax调用:

setTimeout(function() {
    $.ajax(this);
}, 5000);

您是否考虑过在代码的延迟方面使用setTimeout?
function()=
-一些新的语法?:plol抱歉,我刚才在电话上打字,一定是打错了:)我最近使用了很多箭头函数,可能是误用了。非常感谢Daniel和一个简单的问题。我假设有五个锚标记。你知道如何从jquery$(“a.m”)$(“a.o”)中选择特定的锚吗etcI在前面的代码中有一个错误。如何禁用“到”按钮以避免在该请求进行时再次调用