【问题标题】:Getting Dates from URL in PHP and Refreshing Page从 PHP 中的 URL 获取日期并刷新页面
【发布时间】:2015-08-04 15:50:58
【问题描述】:

我正在使用 Google Charts 显示一个折线图,该折线图从 PHP 服务获取数据,该服务根据输入的日期运行查询。查询有效并且它正在获取数据但是当试图将我的日期传递到 url 并用数据取回图表时,我似乎无法思考如何在不离开该页面的情况下“刷新”图表,因为当我提交了我的表单或“日期字段”,它只是转到服务 url.... 这就是我所经历的。

这是我在实际显示图表的索引页面上包含的内容:

  function drawChart() {
      var jsonData1 = $.ajax({
          url: "http://helpdesk/reporting/interface/charts/services/ticketsopenedclosed.php?startDate=<?php print $startDate = $_GET['startDate'] ?>&endDate=<?php print $endDate = $GET_['endDate'] ?>",
          dataType:"json",
          async: false
          }).responseText;

这是我实际拥有我的表单的地方(具有我想用表单中的数据刷新的图表的同一页面!!)

<div><form action="charts/ticketsopenedclosedchart.php" method="get"><div class="well">
            <input type="text" class="span2" value="startDate" data-date-format="yyyy-mm-dd" id="dp2" name="startDate">
            <input type="text" class="span2" value="endDate" data-date-format="yyyy-mm-dd" id="dp3" name="endDate">
          <button type="submit" class="btn btn-default">Refresh Data</button></div></form>
     <div class="container">
       <div class="row">
    </div>
</div>

   </div>
    <?php require("charts/ticketsopenedclosedchart.php")?>
    <div id="ticketsCreated"></div>

因此,很明显,当我单击提交按钮时,它会点击该 url 并提供日期和来自服务的数据。但我想用该数据刷新我的图表,而不是将用户带到它。

【问题讨论】:

    标签: php google-visualization


    【解决方案1】:

    这是因为当您提交表单时,浏览器会原生访问 action 属性中指定的 URL。要解决此问题,您需要按钮上的 onClick 处理程序。

    所以是这样的:

    <button type="submit" class="btn btn-default" onClick="handleRefresh">Refresh Data</button>
    

    然后是JS:

    function handleRefresh(e){
        e.preventDefault();
        drawChart();
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-31
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      相关资源
      最近更新 更多