现在我们正在开发一个混合应用程序,这里的数据是从服务器端访问的,给定的数据是 JSON 格式。从服务器加载数据需要 10 多秒。
这是它的示例代码:
$(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¤cy=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);}
});
});
});
我们如何才能提高性能?