我在Javascript中有以下变量。我想知道如何将这些数据传递给PHP,以便我可以在重定向后显示数据的内容。
postData = {
'dates_ranges': datesAndRanges,
'action':'build',
'output_type': output_type,
'form_html': formHtml,
'width': formBuilder.width(),
'rules':validationRules,
'theme': theme,
};
答案 0 :(得分:1)
使用JQuery post method将数据传递给PHP文件:
$.post("/path/to/script.php", postData, function(result) {
// work with result
});
在PHP中使用$ _POST global来获取变量:
print $_POST['dates_ranges'];
print $_POST['action'];
// ...
答案 1 :(得分:0)
使用jquery它很容易&像这样干净:
$.post('script.php', postData, function(response){
// process/display the server response
});
答案 2 :(得分:0)
你可以使用:
$.post("YOUR_URL", postData, function(response) {
// handle with response
});
或强>
$.ajax({
url: YOUR_URL,
data: postData,
type: 'post',
success: function(response) {
// handle with response
}
});
在你的PHP文件中:
if(isset($_POST) && !empty($_POST)) {
$d = $_POST;
echo $d['date_range']; // and so more
}