doukang2003 2015-06-14 20:26
浏览 67

多个并行AJAX需要较长的服务器响应时间

I have five ajax simultaneously in my .js file. They are taking very long server response time(minimum 5sec). If I call them one by one then each of them executes within 1 sec.

here is my js code.

$j('.combo').change(function(){
        filter_area();
        filter_subarea();
        filter_propertytype();
        filter_pricerange();
        filter_bedrooms();
});

function filter_area()
 {
      var area_id = $j('#inputarea').val();
      var operation = $j('#property').val();
      var subarea_id = $j("#inputsubarea").val();
      var propertytype = $j("#inputpropertytype").val();
      var pricerange = $j("#inputpricerange").val();
      var bedrooms = $j("#inputbedrooms").val();

     $j.ajax({
          type:"GET",
          url:'/custom_action.php',
           data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
      }).done(function(response){         
          $j('#inputarea').html(response);    
      });
 }


function filter_subarea()
 {
      var area_id = $j('#inputarea').val();
      var operation = $j('#property').val();
      var subarea_id = $j("#inputsubarea").val();
      var propertytype = $j("#inputpropertytype").val();
      var pricerange = $j("#inputpricerange").val();
      var bedrooms = $j("#inputbedrooms").val();

     $j.ajax({
          type:"GET",
          url:'/custom_action.php',
           data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
      }).done(function(response){         
          $j('#inputsubarea').html(response);     
      });
 }


function filter_propertytype()
 {
      var area_id = $j('#inputarea').val();
      var operation = $j('#property').val();
      var subarea_id = $j("#inputsubarea").val();
      var propertytype = $j("#inputpropertytype").val();
      var pricerange = $j("#inputpricerange").val();
      var bedrooms = $j("#inputbedrooms").val();

     $j.ajax({
          type:"GET",
          url:'/custom_action.php',
           data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
      }).done(function(response){         
          $j('#inputpropertytype').html(response);    
      });
 }


function filter_pricerange()
 {
      var area_id = $j('#inputarea').val();
      var operation = $j('#property').val();
      var subarea_id = $j("#inputsubarea").val();
      var propertytype = $j("#inputpropertytype").val();
      var pricerange = $j("#inputpricerange").val();
      var bedrooms = $j("#inputbedrooms").val();

     $j.ajax({
          type:"GET",
          url:'/custom_action.php',
           data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
      }).done(function(response){         
          $j('#inputpricerange').html(response);      
      });
 }

function filter_bedrooms()
 {
      var area_id = $j('#inputarea').val();
      var operation = $j('#property').val();
      var subarea_id = $j("#inputsubarea").val();
      var propertytype = $j("#inputpropertytype").val();
      var pricerange = $j("#inputpricerange").val();
      var bedrooms = $j("#inputbedrooms").val();

     $j.ajax({
          type:"GET",
          url:'/custom_action.php',
           data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
      }).done(function(response){         
          $j('#inputbedrooms').html(response);    
      });
 }

Please see images in image1 if I execute all ajax then it takes 4-5 sec to complete all requests. and in image2 I have executed only one ajax out of them then it finished itself within one sec.

image1

image2

and also I have not used any session at my server side script. It is just simple PHP script to handle request and create response.

I have googled to find how to use multiple ajax simultaneously and found the below link-

Two simultaneous AJAX requests won't run in parallel

Since this uses session in server side script, so it has used session_write_close(), but I have no used of any session in my server side script, still I tried to put this function before sending my response, but nothing worked.

Can any one please tell me what I have to do to execute all ajax request concurrently.?

If any thing is not clear please ask.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥15 用visual studi code完成html页面