Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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 使用进度条跟踪多个jquery ajax API请求_Javascript_Jquery_Ajax_Twitter Bootstrap_Progress Bar - Fatal编程技术网

Javascript 使用进度条跟踪多个jquery ajax API请求

Javascript 使用进度条跟踪多个jquery ajax API请求,javascript,jquery,ajax,twitter-bootstrap,progress-bar,Javascript,Jquery,Ajax,Twitter Bootstrap,Progress Bar,我有一个增量,它获取ID并将它们添加到url中,以发出多个ajax请求。 js: for (x = 1; x <= val['id_count']; x++) { $.ajax({ url: baseUrl + x, dataType: "json", success: function(results, status, xhr) { }, error: function(xhr, status, error) { $(&

我有一个增量,它获取ID并将它们添加到url中,以发出多个ajax请求。
js:

for (x = 1; x <= val['id_count']; x++) {
 $.ajax({
    url: baseUrl + x,
    dataType: "json",
    success: function(results, status, xhr) {
   },
    error: function(xhr, status, error) {
    $("#message").html("data: " + status + " " + error)
   }
 })
}
for (x = 1; x <= val['id_count']; x++) {
 totalIDs = 0;
 totalIDs = x.length;
 $.ajax({
    url: baseUrl + x,
    dataType: "json",
    xhr: function() {
      var xhr = new window.XMLHttpRequest();
      xhr.onreadystatechange = function() {
      var progress = x / totalIDs * 100;
      $(".progress-bar").css({
          "width": progress + "%"
        });
      }
     return xhr;
    },
    success: function(results, status, xhr) {
    },
    error: function(xhr, status, error) {
    $("#message").html("data: " + status + " " + error)
   }
 })
}

for(x=1;x
for(x=1;x@rorymcrossan)有限制吗?它看起来很疯狂,但是api没有一次给出所有信息,所以我必须像这样循环它们,而且它有很多请求,需要一些时间,所以我需要看看后台发生了什么。看看-你可以使用.ajaxSend()来增加“进行中"和。ajaxComplete到减量it@freedomn-m谢谢,伙计,我确实读过这些东西,但我是新手,所以我需要更多的解释。看起来你可以将进度更新移到
success:
,而不是
xhr:
-
xhr:
有点高级,你不太可能需要使用它。你可以将
var-inprogress
然后
inprogress++
作为
for
inprogress--
success
inprogress>的
var-progress=(totalIDs-inprogress)/totalIDs*100
的第一行,不幸的是,它不起作用了。或者我犯了一个错误idk
for (x = 1; x <= val['id_count']; x++) {
 totalIDs = 0;
 totalIDs = x.length;
 $.ajax({
    url: baseUrl + x,
    dataType: "json",
    xhr: function() {
      var xhr = new window.XMLHttpRequest();
      xhr.onreadystatechange = function() {
      var progress = x / totalIDs * 100;
      $(".progress-bar").css({
          "width": progress + "%"
        });
      }
     return xhr;
    },
    success: function(results, status, xhr) {
    },
    error: function(xhr, status, error) {
    $("#message").html("data: " + status + " " + error)
   }
 })
}
for (x = 1; x <= val['id_count']; x++) {
 $.ajax({
    url: baseUrl + x,
    dataType: "json",
    success: function(results, status, xhr) {
       if (inprogress < total_urls) {
         inprogress++;
         $("#tProgress").html(inprogress + ' / ' + total_urls + ' ✓');
         progress = Math.round(inprogress / total_urls * 100);
         $("#progress-bar").css({
            "width": progress + "%"
         });
         $("#progress-bar").html(progress + '%');
       }
    },
    error: function(xhr, status, error) {
    $("#message").html("data: " + status + " " + error)
   }
 })
}