我有一個名爲file_with_data_from_server.php
的文件,它從AJAX
調用中收到$_POST['data]
。我設法創建一個新的數組來包含來自服務器的數據。然後這個file_with_data_from_server.php
被包含在另一個.php
文件中。當然,file_with_data_from_server.php
上的所有變量都可以在包含它的文件上訪問,但在我的情況下,我無法訪問變量,其中的值取自json_decoded
數據。這是file_with_data_from_server.php
代碼,變量不能在PHP中訪問
$data_for_reports = $_POST['data']; // data from server
$rrow = json_decode($data_for_reports);
$dates_for_reports = array();
foreach($rrow as $rr){
$dates_for_reports[] = $rr->time_period;
}
$current_date_with_data = end($dates_for_reports); // this contains data like '201301'
我
.php
文件,其中包括我
file_with_data_from_server.php
,我有這樣的代碼,
include('file_with_data_from_server.php');
echo '<pre>';
print_r('test'.$current_date_with_data);
echo '</pre>';
我想打印的$current_date_with_data
變量的值,但它不顯示任何內容。
您是否嘗試轉儲該變量(在第一個文件中)? – Uby 2013-03-21 20:20:41
@Uby,當然有它的數據。 – 2013-03-21 20:21:28
所以你發佈到'file_with_data_from_server.php',但包括它在另一個.php頁面? – juco 2013-03-21 20:27:52