【问题标题】:Parallel Ajax Requests in Jquery With Progress Bar带有进度条的 Jquery 中的并行 Ajax 请求
【发布时间】:2014-04-11 10:20:51
【问题描述】:

根据用户操作,我需要进行从一次调用到三个并行调用的 ajax 调用。我也想为此显示进度条。任意数量的 Ajax 请求的一个进度条。以下是我要调整的示例代码。谁能建议我如何限制通话次数以及如何使用一个进度条。

  $.when(
 // Get the HTML
  $.get("/feature/", function(html) {
  globalStore.html = html;
 }),

 // Get the CSS
 $.get("/assets/feature.css", function(css) {
globalStore.css = css;
 }),

 // Get the JS
 $.getScript("/assets/feature.js")

 ).then(function() {

  // All is ready now, so...

  // Add CSS to page
     $("<style />").html(globalStore.css).appendTo("head");

     // Add HTML to page
   $("body").append(globalStore.html);

 });

【问题讨论】:

    标签: jquery progress-bar


    【解决方案1】:

    试试这个

    jQuery $.when() 和 $.done() 正是你所需要的:

    $.when($.ajax("/page1.php"), $.ajax("/page2.php")) .then(myFunc, myFailure);

    【讨论】:

      【解决方案2】:

      否则你可以试试这个 你可以做这样的事情

      var allData = [] $.getJSON("/values/1", function(data) { allData.push(数据); 如果(数据长度 == 2){ processData(allData) // 其中流程数据处理所有数据 } });

      $.getJSON("/values/2", function(data) { allData.push(数据); 如果(数据长度 == 2){ processData(allData) // 其中流程数据处理所有数据 } });

      var processData = 函数(数据){ 变量总和 = 数据 [0] + 数据 [1] $('#mynode').html(sum); }

      【讨论】:

        【解决方案3】:

        试试这个:

          var ajax1 = function(){jQuery.ajax({......})};
          var ajax2 = function(){jQuery.ajax({......}};
          function loadMultipleAjax(){
                                       //add loading statement
                                     jQuery.when(ajax1,ajax2)
                                     .done(function(){
                                        //remove loading statement
                                   })};
        
        
         //call 
        loadMultipleAjax();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-04-20
          • 1970-01-01
          • 1970-01-01
          • 2010-10-22
          • 2012-10-11
          • 2010-10-29
          • 1970-01-01
          • 2012-05-18
          相关资源
          最近更新 更多