0
叫我到PHP函數調用Ajax爲:PHP函數沒有獲得通過Ajax
$.ajax({
url: 'Link',
type: 'POST',
dataType : 'json',
data: {'txtFromOrderDate' : '2014-08-01','txtToOrderDate' : '2014-08-05'},
success: function() {
window.location = 'Link';
}
});
PHP函數爲:
public function createZipAction($txtFromOrderDate,$txtToOrderDate)
{
date_default_timezone_set('Australia/Melbourne');
$date = date('m:d:Y H:i:s', time());
$exportBatch = $date;
$order = $this->getTableGateway('order');
$select = new Select();
$select->from('order')
->join('user', 'order.user_id = user.id', array('email'))
->where ("order.created between ".$txtFromOrderDate." and '2014-08-03' ");
//->where ('order.created between '.$txtFromOrderDate.' and '.$txtToOrderDate);
$data = $order->selectWith($select)->toArray();
$batchDir = __DIR__ . '/../../../../../data/export/batch/' . $exportBatch;
if(is_dir($batchDir) == false)
mkdir($batchDir);
$csvFile = fopen($batchDir . '/order.csv', 'w');
$i = 0;
foreach($data as $record) {
if($i==0) fputcsv($csvFile, $this->getCsvHeader($record));
fputcsv($csvFile, $this->updateCsvLine($record));
$pngTmpFile = $this->saveTmpImage($record['plate_id']);
$this->savePlatePdf($pngTmpFile, $exportBatch, $record['id']);
unlink($pngTmpFile);
$i++;
}
fclose($csvFile);
$filter = new \Zend\Filter\Compress(array(
'adapter' => 'Zip',
'options' => array(
'archive' => $batchDir . '.zip'
)
));
$filter->filter($batchDir);
$fileToDownload=$batchDir . '.zip';
$this->downloadOrderCSVAction($fileToDownload);
echo "exported: $i records.";
die();
}
這裏的時候,我提供日期此功能,它沒有得到日期。
但是,當我在PHP函數寫日期硬編碼爲:按預期工作
$txtFromOrderDate='2014-08-01'
$txtToOrderDate='2014-08-05'
然後進一步的功能。
可能是什麼問題???
請幫幫我。
'$ txtFromOrderDate = $ _ POST [ 'txtFromOrderDate'];'等等......當你郵寄到PHP,這些變量沒有被設置爲全局變量,但$ _POST數組中設置。 – naththedeveloper 2014-10-27 09:28:25
向我們展示您使用POST變量提供方法的代碼。此外,查詢似乎不安全。有人可以向腳本發送惡意日期(即SQL代碼)並執行一些令人討厭的事情。在使用前你應該清理輸入。 – 2014-10-27 09:31:14