简体   繁体   English

如何加载具有动态内容的html页面?

[英]How to load html page with dynamic content?

I am trying to load one html page which reads json file using Jquery getJSON() function. 我正在尝试加载一个HTML页面,该页面使用Jquery getJSON()函数读取json文件。

sample.html sample.html

    <html>
<head>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
    <script src="http://code.highcharts.com/stock/highstock.js"></script>
        <script src="http://code.highcharts.com/modules/heatmap.js"></script>
    <script>

   $(document).ready(function() {

    var options = {
        chart: {
            renderTo: 'container',
            type: 'heatmap',
            zoomType:'x',
            plotWidth:400,
            plotHeight:400
        },
          title: {
            text: ''
        },

        xAxis: {
            categories: ['AA11230', 'AA11231', 'AA11232', 'AA11233', 'AA11234', 'AA11235']
        },

        yAxis: {
            categories: ['AA11230', 'AA11231', 'AA11232', 'AA11233', 'AA11234', 'AA11235'],
            title: null
        },

        colorAxis: {
            min: 0,
            minColor: '#FFFFFF',
            maxColor: Highcharts.getOptions().colors[0]
        },

        legend: {
            align: 'right',
            layout: 'vertical',
            margin: 0,
            verticalAlign: 'top',
            y: 25,
            symbolHeight: 280
        },
        plotOptions:{
                   series:{
                          turboThreshold: 0
                          }
        },
        series: [{}]
    };

    $.getJSON('sample2.json', function(data) {
        options.series[0].data = data;
        var chart = new Highcharts.Chart(options);
    });

});

    </script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 600px; margin: 0 auto"></div>
</body>
</html>

sample2.json sample2.json

[[1, 2, 1],
[2, 3, 1],
[3, 4, 0.9],
[4, 5, 0.7],
[5, 6, 0.9],
[1, 3, 0.1],
[2, 4, 0.3],
[3, 5, 0.4],
[4, 6, 0.8],
[1, 4, 1],
[2, 5, 0.9],
[3, 6, 0.8],
[1, 5, 0.9],
[2, 6, 0.6],
[1, 6, 0.1]
]

index.html index.html

     <html> 
      <script> 
         $(function(){ $("#plots-tabs-C").load("sample.html");   });       </script> 
    <body> 
      <div id="plots-tabs" class="plots-tabs" style="padding-top: 10px; padding-bottom: 10px"> 


      <ul id="plots-tabs-header" class="plots-tabs-header"> 
          <li class="plots-tabs-tab"><a href="#plots-tabs-A">PLOT A</a></li> 
          <li class="plots-tabs-tab"><a href="#plots-tabs-B">PLOT B</a></li> 
          <li class="plots-tabs-tab"><a href="#plots-tabs-C">PLOT C</a></li> 
      </ul>  

      <div id="plots-tabs-body" class="plots-tabs-body"> <div id="plots-tabs-A"  class="plots-tabs-body-content" style="margin: 0px; padding: 0px;">    </div>      
      <div id="plots-tabs-B" class="plots-tabs-body-content"></div> 
      <div id="plots-tabs-C" class="plots-tabs-body-content"></div> 
     </div> 
    </div>
  </body> 
  </html>

But on clicking PLOT C it does not load data(sample2.json) automatically. 但是,单击PLOT C不会自动加载数据(sample2.json)。 How can i fix this problem? 我该如何解决这个问题?

you might try wrapping your load call in a click event: 您可以尝试将加载调用包装在click事件中:

$("#plots-tabs-C").click( function(){ $("#plots-tabs-C").load("sample.html");   } );

Also, it looks like you've got an extra div close tag in your index.html. 另外,似乎您的index.html中还有一个额外的div关闭标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM