php post 并同时重定向页面

php post and redirect page same time

我不是 php 专家,但我被困在这里了。我有以下三个 .php 个文件

  1. index.php <- 下拉列表,其中 select DB table.

  2. query.php <- 它制作 json 查询。

  3. chart.php <- 这是高图 JQuery 页面。它使用 $.getJSON("query.php", function(json) { 函数从 query.php 文件中获取数据。

index.php 将从 select DB/Table 的下拉列表中获取用户输入并将其传递给 query.php 并设置 SELECT * FROM $table 变量。

但我想做 POST,同时它会打开 chart.php 页面,这样我就可以直接重定向到图表页面。我如何同时发送 POST 和重定向,以便 query.php 获得 $table 变量并立即 chart.php 打开图表。

编辑:

如果我将所有 query.php 代码放在 chart.php 中,那么我如何将那些 json 值放在 $.getJSON() 中?

$.getJSON("query.php", function(json) {
                options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];
                options.series[1] = json[2];
                options.series[2] = json[3];
                chart = new Highcharts.Chart(options);
            });

$.getJSON() 如何从变量中获取值?

1) 来自 index.php -> 使用所需参数POST 向 chart.php 发出请求

2) 在 chart.php 上使用 $_POST => 从 index.php 接收数据并在模板上显示,例如:

对于 query.php

的 GET 请求
$.getJSON("query.php?<?='param1='.$_POST['param1']?>", function(json) {
                options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];
                options.series[1] = json[2];
                options.series[2] = json[3];
                chart = new Highcharts.Chart(options);
            });

或使用通常的 $.ajax 请求通过 POST 请求发送:

$.ajax({ 
         url: 'query.php',
         data: "<?='param1='.$_POST['param1']?>"
         dataType : "json",
         method:"POST",
         success: function(json){
                options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];
                options.series[1] = json[2];
                options.series[2] = json[3];
                chart = new Highcharts.Chart(options);
});

更新

如果您的服务器没有 short_open_tag=On - 使用 <?php echo 'param1='.$_POST['param1'] ?>

并在将参数添加到模板之前检查参数