[英]php post and redirect page same time
I am not php expert but i get stuck here. 我不是PHP专家,但我被困在这里。 I have following three
.php
files 我有以下三个
.php
文件
index.php <- drop down list, which select DB table. index.php <-下拉列表,选择数据库表。
query.php <- it craft json query. query.php <-它制作json查询。
chart.php <- it's highchart JQuery page. chart.php <-它是highchart JQuery页面。 which use
$.getJSON("query.php", function(json) {
function to fetch data from query.php
file. 使用
$.getJSON("query.php", function(json) {
函数从query.php
文件中获取数据。
index.php
will get user input from drop-down list of select DB/Table and pass it to query.php
and set SELECT * FROM $table
variable. index.php
将从选择数据库/表的下拉列表中获取用户输入,并将其传递给query.php
并设置SELECT * FROM $table
变量。
But i want to do POST
and at same time it will open chart.php
page so i can direct redirect to chart page. 但是我想做
POST
,同时它将打开chart.php
页面,这样我就可以直接重定向到图表页面。 How i send POST and Redirect same time so query.php
get $table variable and instantly chart.php
open chart. 我如何同时发送POST和重定向,所以
query.php
获得$ table变量并立即chart.php
打开图表。
If i put all my query.php
code inside chart.php
then how do i put those json values in $.getJSON()
? 如果我将所有
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);
});
how $.getJSON()
will get value from variable? $.getJSON()
如何从变量获取值?
1) from index.php -> make POST request to chart.php with needed parameters 1)从index.php->使用所需的参数向chart.php发出POST请求
2) using $_POST on chart.php => receive data from index.php and show on template like : 2)在chart.php上使用$ _POST =>从index.php接收数据并显示在模板上,如:
for GET request to query.php 用于GET请求到query.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);
});
or using usual $.ajax request send via POST request: 或使用通过POST请求发送的常规$ .ajax请求:
$.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);
});
UPDATE UPDATE
If your server don't have short_open_tag=On - use <?php echo 'param1='.$_POST['param1'] ?>
如果您的服务器没有short_open_tag = On-使用
<?php echo 'param1='.$_POST['param1'] ?>
And check params before giving them on template 并在将参数提供给模板之前检查参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.