gpt4 book ai didi

javascript - 如何检索对 php 变量的 jquery ajax 响应?

转载 作者:行者123 更新时间:2023-11-30 12:52:26 24 4
gpt4 key购买 nike

如何在成功后将 jquery ajax 响应传递到 php 变量中。这是我的代码:

进程.php

    $start = "";
$end = "";
if(isset($_POST['tampStart']))
{
$start = $_POST['tampStart'];
}
if(isset($_POST['tampEnd']))
{
$end = $_POST['tampEnd'];
}

$SQL = "SELECT * FROM `values` WHERE date BETWEEN '".$start."' and '".$end."'";
$result = mysql_query($SQL);

$prefix = '';
while ( $row = mysql_fetch_assoc( $result ) ) {
$prefix .= "[\n"."'".$row['month']."'".', '.$row['days']."]".",";
}

echo rtrim($prefix, ",");

索引.php

    var dStart = $('#textInput1').val();
var dEnd = $('#textInput2').val();

var form_data = {
tampStart: dStart,
tampEnd: dEnd
};

$.ajax({
url: 'process.php',
type: 'POST',
async : true,
data: form_data,
dataType: 'text',
success: function(resp){
$('#content').html(resp);
//pass to php variable ?
}
});

当我将响应放入div ($('#content').append(resp); 时没有问题,但是如何将响应放入php 变量。感谢您的提前..

更新我的 Highcharts 代码:

function createChart(datan) {
//alert(datan);
Highcharts.setOptions({
lang: {
drillUpText: 'Back to {series.name}'
}
});

var options = {

chart: {
height: 300
},

title: {
text: 'Highcharts Drilldown Plugin'
},

xAxis: {
categories: true
},

drilldown: {
series: [{
id: 'fruits',
name: 'Fruits',
data: [datan] //here #*
}, {
id: 'cars',
name: 'Cars',
data: [{
name: 'Toyota',
y: 4,
drilldown: 'toyota'
},
['Volkswagen', 3],
['Opel', 5]
]
}, {
id: 'toyota',
name: 'Toyota',
data: [
['RAV4', 3],
['Corolla', 1],
['Carina', 4],
['Land Cruiser', 5]
]
}]
},

legend: {
enabled: false
},

plotOptions: {
series: {
dataLabels: {
enabled: true
},
shadow: false
},
pie: {
size: '80%'
}
},

series: [{
name: 'Overview',
colorByPoint: true,
data: [{
name: 'Fruits',
y: 10,
drilldown: 'fruits'
}, {
name: 'Cars',
y: 12,
drilldown: 'cars'
}, {
name: 'Countries',
y: 8
}]
}]
};

// Column chart
options.chart.renderTo = 'container1';
options.chart.type = 'column';
var chart1 = new Highcharts.Chart(options);

}

我将 highcharts 配置为一个函数。当我警告(datan)时,它显示了来自 ajax 响应的数据,但是当我打开 Drilldown 选项数据时(参见上面的符号 #*),highchart 配置无法读取它..

最佳答案

PHP 在服务器上运行,而不是在客户端上运行,因此您要求的东西只能在服务器上运行。您必须根据需要自定义此代码,它提供了框架。

$.ajax({
url: 'process.php',
type: 'POST',
async : true,
data: form_data,
dataType: 'text',
success: function(resp){
// $('#content').html(resp);
createChart(resp);
}
});
var chart;
function createChart(data) {
var options = {

chart: {
height: 300
},

title: {
text: 'Highcharts Drilldown Plugin'
},

xAxis: {
categories: true
},

drilldown: {
series: data}
};


options.chart.renderTo = 'content';
options.chart.type = 'column';
var chart1 = new Highcharts.Chart(options);



}

关于javascript - 如何检索对 php 变量的 jquery ajax 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20487289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com