javascript - Ajax not making function call to php function -



javascript - Ajax not making function call to php function -

i have ajax function in script as:

$.ajax({ url: 'http://www.somesitename.com/admin/exporttocsvaction', type: 'get', data:{}, cache: false, success: function() { alert("sucess"); }, error: function () { alert("error"); } });

exporttocsvaction function in php as:

public function exporttocsvaction() { $exportbatch = 10; $order = $this->gettablegateway('order'); $select = new select(); $select->from('order'); $data = $order->selectwith($select)->toarray(); $batchdir = __dir__ . '/../../../../../data/export/batch/' . $exportbatch; mkdir($batchdir); $filenamewithfilepath=$batchdir . '/order2.csv'; if (file_exists($filenamewithfilepath)) { $this->downloadordercsvaction($filenamewithfilepath); } else { $csvfile = fopen($batchdir . '/order2.csv', 'w'); $i = 0; foreach($data $record) { if($i==0) fputcsv($csvfile, $this->getcsvheader($record)); fputcsv($csvfile, $this->updatecsvline($record)); $i++; } fclose($csvfile); } }

but every time returning me error alert.

when run straight through link:

http://www.somesite.com/admin/exporttocsvaction

it returns me result correctly. (downloads file expected)

but through ajax gives me error alert.

through inspect element network tab following:

please help me.

where making mistake?

note:

i tried removing info ajax, no effect

edit :

$.ajax({ url: 'http://www.somesitename.com/admin/exporttocsv', type: 'get', data:{}, cache: false, success: function() { alert("sucess"); }, error: function () { alert("error"); } }); exporttocsvaction function in php as: public function exporttocsvaction() { $exportbatch = 10; $order = $this->gettablegateway('order'); $select = new select(); $select->from('order'); $data = $order->selectwith($select)->toarray(); $batchdir = __dir__ . '/../../../../../data/export/batch/' . $exportbatch; mkdir($batchdir); $filenamewithfilepath=$batchdir . '/order2.csv'; if (file_exists($filenamewithfilepath)) { //code download file } else { $csvfile = fopen($batchdir . '/order2.csv', 'w'); $i = 0; foreach($data $record) { if($i==0) fputcsv($csvfile, $this->getcsvheader($record)); fputcsv($csvfile, $this->updatecsvline($record)); $i++; } fclose($csvfile); } }

now code getting alet sucess. not downloading file

you're getting 404, either there's routing issue controller, or there's fatal error somewhere in controller action. 1 way debug controller action seek putting error_log @ origin of exporttocsvaction function, like:

error_log("beginning of function");

then check apache error log , see if logged error. if log error, seek putting error_log statement after other statements within function , see if logged. you'll know statement causing script die if error not logged.

javascript php jquery ajax

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -