Yii Framework Forum: [Solved] File Download From Ajaxsubmit - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Solved] File Download From Ajaxsubmit ajax button does not download file Rate Topic: -----

#1 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 24 March 2013 - 05:25 AM

I am unable to download a file using an ajaxsubmit button
echo CHtml::ajaxSubmitButton('Export to Excel',$this->createUrl('/agent/Payment/ExcelExport'))


In actionExcelExport, i am using CFile extension to download file
$file=Yii::app()->file->set($path, true); //using CFile extension
$file->send('report.xlsx', false);


I believe there is not any issue with the CFile extension, because If i directly call action /agent/Payment/ExcelExport, then the file is downloaded successfully.

Please guide where is the issue.

regards,
Shahzad
0

#2 User is offline   mrk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 07-March 11

Posted 24 March 2013 - 10:28 AM

Do you send some post/get data to this url, using form under which you have this ajaxSubmitButton?
0

#3 User is offline   Jorgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 22-March 13

Posted 25 March 2013 - 01:08 PM

Press F12 or open Firebug and in Console see what is the request and what is the answer.
0

#4 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 30 March 2013 - 01:05 AM

View PostJorgee, on 25 March 2013 - 01:08 PM, said:

Press F12 or open Firebug and in Console see what is the request and what is the answer.


In chrome i have following in header
Request URL:http://localhost/mts/index.php?r=agent/Payment/ExcelExport
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:292
Content-Type:application/x-www-form-urlencoded
Cookie:PHPSESSID=tqp3ujt1e47km2kgnrspfv8bn7
Host:localhost
Origin:http://localhost
Referer:http://localhost/mts/index.php?r=agent/Payment/admin
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
r:agent/Payment/ExcelExport
Form Dataview sourceview URL encoded
PaymentSearch[agent_id]:
PaymentSearch[insert_date]:
PaymentSearch[pin_number]:
PaymentSearch[customer_id]:
PaymentSearch[beneficiary_id]:
PaymentSearch[company_id]:
PaymentSearch[amount_due_lc]:
PaymentSearch[amount_due_fc]:
PaymentSearch[payment_status]:
Response Headersview source
Cache-Control:private
Connection:Keep-Alive
Content-Disposition:attachment;filename="report.xlsx"
Content-Length:0
Content-Transfer-Encoding:binary
Content-Type:application/octet-stream
Date:Sat, 30 Mar 2013 05:59:52 GMT
Expires:Mon, 26 Jul 1997 05:00:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:private
Server:Apache/2.2.22 (Win32) PHP/5.3.13
X-Powered-By:PHP/5.3.13
X-Sendfile:C:\wamp\www\mts\files\temp\report3.xlsx

Nothing is shown in preview and response tabs.
0

#5 User is offline   mrk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 07-March 11

Posted 30 March 2013 - 08:06 AM

Is this data

PaymentSearch[agent_id]:
PaymentSearch[insert_date]:
PaymentSearch[pin_number]:
PaymentSearch[customer_id]:
PaymentSearch[beneficiary_id]:
PaymentSearch[company_id]:
PaymentSearch[amount_due_lc]:
PaymentSearch[amount_due_fc]:
PaymentSearch[payment_status]:


indeed empty ? Or you just cleared it in this example? Because if you don't send anything in post, then solution is very easy. Instead of triggering form submission under given url and trying to do something with response that contain binary data, it's much easier to just execute this one line of code, when the button is clicked:
window.location = "http://localhost/mts/index.php?r=agent/Payment/ExcelExport"
.
0

#6 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 30 March 2013 - 09:40 AM

Ok, i have done it without ajaxSubmit, used simple submit button.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users