Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
Jquery 一种优化多个的方法。每个都使用ajax json请求?_Jquery_Ajax_Dom - Fatal编程技术网

Jquery 一种优化多个的方法。每个都使用ajax json请求?

Jquery 一种优化多个的方法。每个都使用ajax json请求?,jquery,ajax,dom,Jquery,Ajax,Dom,我有很多图表(hightchart)要在同一页中生成,加载我的所有图表至少需要5-6秒 Html页面: <div class="graph_score" title="2" > <div class="graph_score" title="3" > <div class="graph_score" title="4" > <div class="graph_score" title="5" > .... ...

我有很多图表(hightchart)要在同一页中生成,加载我的所有图表至少需要5-6秒

Html页面:

    <div class="graph_score" title="2" >
    <div class="graph_score" title="3" >
    <div class="graph_score" title="4" >
    <div class="graph_score" title="5" >
....

....
我的jquery:

    $(".graph_score").each(function() {
      id_graph = $(this).attr("title");

      $.getJSON('http://' + document.domain + '/school/teachers/generate_score/graph' + id_graph, function(data) {
            options = data;
            options.tooltip = {
            formatter: function() {
                var extrafield = this.series.options.extrafield;
                var extrafield2 = this.series.options.extrafield2;
                var extrafield3 = this.series.options.extrafield3;
                return '<b> Note: ' + this.y + ' % <br/>' + '<b>Nom de l\'examen:</b>' + extrafield[this.point.x - 1] + '</b><br/><b>Pondération</b>' + extrafield2[this.point.x - 1] + "<br /><b>Date</b>" + extrafield3[this.point.x - 1];
            }
            }
            chart = new Highcharts.Chart(options);
        });

    })
$(“.graph\u score”)。每个(函数(){
id_graph=$(this.attr(“title”);
$.getJSON('http://'+document.domain+'/school/teachers/generate_score/graph'+id_graph,函数(数据){
选项=数据;
选项。工具提示={
格式化程序:函数(){
var extrafield=this.series.options.extrafield;
var extrafield2=this.series.options.extrafield2;
var extrafield3=this.series.options.extrafield3;
返回'Note:'+this.y+'%
'+'Nom de l'examen:'+extrafield[this.point.x-1]+'
Pondération'+extrafield2[this.point.x-1]+“
Date”+extrafield3[this.point.x-1]; } } 图表=新的高点图表。图表(选项); }); })
我可以做些什么来加快这个页面的渲染速度吗

*我知道问题是我的脚本调用8次http://'+document.domain+/'/school/teachers/generate_score所以它的8 DOM请求。。。。。但我不知道如何优化它


Thx

如果您认为网络传输需要很长时间,那么您可以在服务器上创建一个新函数,获取ID列表并返回多个结果。

尝试向脚本中添加一些计时器,以查看瓶颈所在-它要么是在AJAX请求中检索数据,要么是显示数据。我猜是AJAX花了很多时间。看看加快服务器端代码速度的方法。另外,您可以在一次调用中返回图形的所有数据,然后分别解析每个图形的JSON。同样,这取决于服务器的速度以及它接受的连接数量,这是否会带来好处。此外,您还需要确保您的Web服务器正在压缩数据(因此传输的数据较少)