dongshiliao7990 2018-07-20 04:08
浏览 126
已采纳

重新加载然后刷新相同的函数jquery

In my PHP application I'm using 2 php files.

  1. chart.php - Page contains a google chart.

    <div id="chart_div" style="height:100%;width:100%">
    </div>
    
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawStuff);
    
      function drawStuff() {
        var data = new google.visualization.arrayToDataTable([
          ['Opening Move', 'Percentage'],
          ["King's pawn (e4)", 44],
          ["Queen's pawn (d4)", 31],
          ["Knight to King 3 (Nf3)", 12],
          ["Queen's bishop pawn (c4)", 10],
          ['Other', 3]
        ]);
    
        var options = {
          title: 'Chess opening moves',
          width: 900,
          legend: { position: 'none' },
          chart: { title: 'Chess opening moves',
                   subtitle: 'popularity by percentage' },
          bars: 'horizontal', // Required for Material Bar Charts.
          axes: {
            x: {
              0: { side: 'top', label: 'Percentage'} // Top x-axis.
            }
          },
          bar: { groupWidth: "90%" }
        };
    
        var chart = new google.charts.Bar(document.getElementById('chart_div'));
        chart.draw(data, options);
            google.visualization.events.addListener(chart, 'select', selectHandler);
      };
    
      function selectHandler() {
         window.location.href = "chart.php";
      }
    </script>
    

2. index.php - Home page where I'm including chart.php in a div

<div style="width:40%">
require_once 'chart.php';
</div>

On clicking the chart in index.php page , it will call selectHandler() and redirect to chart.php.

The issue is, the chart in chart.php (after redirecting from index.php) is showing in small size similar to the chart display in index.php. Once I refreshes the chart.php it will display the chart in correct size.

Is there any function in jquery to refresh a page by reloading other than using location.reload().

Can anyone help me to fix this issue? Thanks in advance.

展开全部

  • 写回答

1条回答 默认 最新

  • dongshen9058 2018-07-20 05:07
    关注

    try redrawing the chart,
    use an inline function on your select handler,
    so you can still access your chart, data, and options.

    google.visualization.events.addListener(chart, 'select', function () {
      window.location.href = "chart.php";
      chart.draw(data, options);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部