提高数据检索JSON格式的性能 [英] Improve the performance of Data retrieving in JSON format

查看:81
本文介绍了提高数据检索JSON格式的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我们正在开发的混合应用程序,并在此数据从服务器端访问和给出的数据是JSON格式。其时间超过10秒,从服务器加载数据。

Now We are developing a Hybrid App and here data is accessing from Server side and given data is in JSON format. Its takes more than 10 seconds to load the data from server.

下面是它的样本code:

Here is its sample code :

$(document).ready(function(){
    $("#cardetails").tap(function(event,ui){   

      $.ajax({       
          url:'http://wwwsampleurl.net/json/jsn_cmp.php?json=1&rcg_mobile=2&lan=en&callback=ajax_eup&pick_up_loc=AGPT01&drop_off_loc=AGPT01&country_des=ES&country_user=AE&currency=EUR&day_drop=Tue&day_pick=Tue&age_driver=30&uid=0&num_days=7&pick_up=2722&drop_off=2722&pick_up_day=13&pick_up_hour=10&pick_up_minute=00&pick_up_mon=08&pick_up_year=2013&drop_off_day=20&drop_off_hour=10&drop_off_minute=00&drop_off_mon=08&drop_off_year=2013',
          data:'',
          contentType: "application/json; charset=utf-8",
          type: "POST",
          dataType: "json",
          crossDomain:true,
          cache: false,
          async:false,
          success: function(data, textStatus, jqXHR){
              $.each(data, function(index, val) {
                  if(index=='gen'){
                      alert("gen data - "+val.pick_up_day);
                  }
                  else if(index=='company_date'){//alert('Load cars')
                      for (var i = 0, len = val.length; i < len; i++) {

                          //alert(JSON.stringify(val[i]));   
                          //    alert(val[i].car_img);
                          $('#carImages').append('<img src="'+val[i].car_img+'" width="70" height="110" alt="'+val[i].car_group+'" title="'+val[i].type+'"/>');
                       }
                   }

               });

           },
           error: function(XMLHttpRequest, textStatus, errorThrown){alert(textStatus +"-"+ errorThrown);}

        });       
    });

});

我们怎样才能提高性能?​​

How we can improve the performance?

推荐答案

由于previous说你应该建立一个内部变量,并在循环后添加到DOM。

As previous said you should build up an internal variable and add it to the DOM after the loop.

也许你可以优化在服务器端了一下,如果(指数=='根')是一个有点昂贵。很难说wothout看到来自服务器的数据。

Maybe you could optimize a bit on the server side, the if(index=='gen') is a bit costly. Hard to say wothout seeing the data that comes from the server.

这篇关于提高数据检索JSON格式的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆