javascript - 重新加载然后在同一函数jquery中刷新

标签 javascript php jquery google-visualization reload

在我的 PHP 应用程序中,我使用了 2 个 php 文件。

  1. chart.php - 页面包含一个 google 图表。

    <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 - 我将 chart.php 包含在 div 中的主页

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

点击 index.php 页面中的图表,它会调用 selectHandler() 并重定向到 chart.php。

问题是,chart.php 中的图表(从 index.php 重定向后)显示为小尺寸,类似于 index.php 中的图表显示。刷新 chart.php 后,它将以正确的大小显示图表。

除了使用 location.reload() 之外,jquery 中是否有任何通过重新加载来刷新页面的函数。

谁能帮我解决这个问题?提前致谢。

最佳答案

尝试重新绘制图表,
在您的选择处理程序上使用内联函数,
这样您仍然可以访问您的图表、数据和选项。

google.visualization.events.addListener(chart, 'select', function () {
  window.location.href = "chart.php";
  chart.draw(data, options);
});

关于javascript - 重新加载然后在同一函数jquery中刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51442213/

相关文章:

javascript - jQuery 检查 id 是否有字符串

javascript - 如何使用 javascript 获取 HTML 评论

javascript - 如何正确地为我的变量创建 for 循环?

php - Laravel 5.4 多重身份验证 - Auth::guard()->user() 空

php - 根据本地计算机上的用户时间戳更改样式表。 Javascript 解决方案?

javascript - 下载本地文件

javascript - HTML 按钮和 Controller 未连接

php - $_GET、$_POST 和 $_REQUEST 未填充

javascript - 并发 jquery jsonp 响应被发送到错误的成功处理程序

javascript - 如何在javascript中按日期范围过滤json数据