如何保存" exportURL +数据"数据到php变量? ajax代码在同一个php文件中,我需要将这些数据存储在php变量中。 目前它只显示包含数据的警报,但我想将其存储在php变量中。
// URL to Highcharts export server
var exportUrl = 'https://export.highcharts.com/';
// POST parameter for Highcharts export server
var object = {
options: JSON.stringify(options),
type: 'image/png',
async: true
};
// Ajax request
$.ajax({
type: 'post',
url: exportUrl,
data: object,
success: function (data) {
//Save here in a php variable so i can use the value in the php code that follows in my file
}
});
答案 0 :(得分:0)
如果我了解你想要从提交给外部服务器的ajax中捕获数据并写入你的服务器,那么正确吗?
// URL to Highcharts export server
var exportUrl = 'https://export.highcharts.com/';
options = {};
// POST parameter for Highcharts export server
var object = {
options: JSON.stringify(options),
type: 'image/png',
async: true
};
// Ajax request
$.ajax({
type: 'post',
url: exportUrl,
data: object,
success: function (data) {
//Submit data from your server
// Ajax request
$.ajax({
type: 'post',
url: 'http://localhost/teste.php',//this your local file
data: {'data' : exportUrl+data},
success: function (data2) {
//Response from your server
//if your teste.php print response. echo "" or die("") ;
}
});
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
<?php
//this variable post contains your data sended from ajax
//print_r($_POST);
$data = $_POST['data']
?>