【问题标题】:jQuery AJAX queue not getting responsejQuery AJAX 队列没有得到响应
【发布时间】:2018-08-08 12:42:36
【问题描述】:

我有一个数组,里面有 100 个项目,每个项目都应该发出一个 ajax 请求问题是服务器停止了 DDosAttack 所以我应该在队列中提出请求,但我不知道为什么我的响应是空的,直到所有请求都已完成。

array.map((row, index, arr)=> {
              return $.ajax({
                type: 'post',
                async: false, // this caused the problem
                url: 'url',
                data: {...},
                success: function(data){  
                  console.log(data) //  appears only when all the requests is done
                },
                error: function(data){
                   console.log(data) //  appears only when all the requests is done
                }
              })

          })

【问题讨论】:

  • 问题是因为你使用的是async: false,所以虽然所有的AJAX请求一个接一个地发生,但它完全阻止了浏览器在请求进行时更新UI。当然,您可以通过多种方式解决此问题,但无论有任何修复,这都是一个有很大缺陷的解决方案。您的 DDOS 问题仍然存在,只是稍微难以解决。要正确解决此问题,请发出一个请求,改为获取 all 所需的数据。
  • @RoryMcCrossan 哇,非常感谢您的精彩解释

标签: javascript jquery ajax queue


【解决方案1】:

我使用了ajaxq 存储库,它非常有用

https://code.google.com/archive/p/jquery-ajaxq/downloads

array.map((row, index, arr)=> {
              return $.ajaxq('queue',{
                type: 'post',
                url: 'url',
                data: {...},
                success: function(data){  
                  console.log(data) //  appears only when all the requests is done
                },
                error: function(data){
                   console.log(data) //  appears only when all the requests is done
                }
              })

          })

【讨论】:

    猜你喜欢
    • 2014-04-10
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    相关资源
    最近更新 更多