我不是php专家,但我被困在这里了。我有以下三个.php
文件
-
index.php<-下拉列表,其中选择DB表。
-
query.php<-它制作json查询。
-
chart.hp<-这是图表JQuery页面。使用CCD_ 2函数从CCD_。
index.php
将从选择DB/Table的下拉列表中获得用户输入,并将其传递给query.php
并设置SELECT * FROM $table
变量。
但我想做POST
,同时它会打开chart.php
页面,这样我就可以直接重定向到图表页面。我如何同时发送POST和Redirect,以便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->使用所需参数向chart.php发出POST请求
2) 在chart.php上使用$_POST=>从index.php接收数据并在模板上显示,如:
用于查询的GET请求。php
$.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=打开-请使用<?php echo 'param1='.$_POST['param1'] ?>
在模板上给出参数之前检查参数