Hello,

I'm writing an app that at some point has a text string dynamically 
generated in a view via javascript.
What I would like to do is download that text as a file.
For that purpose my attempted approach has been...:

- on the same js function that generates the string I call:

ajax('download_test?content='+content, [], '');


and on the controller I have:


def download_test():
        
    content = request.vars.content
        
    response.headers['Content-Type'] = 'text/csv'
    attachment = 'attachment;filename=data.csv'
    response.headers['Content-Disposition'] = attachment
    
    raise HTTP(200,str(content),
                   **{'Content-Type':'text/csv',
                      'Content-Disposition':attachment + ';'})


I've tried several variations around this approach, and the only thing that 
I can confirm is that the desired content is effectively passed from the 
the view to the controller (and back to the view if I define a container as 
the 3rd parameter of the ajax() function, but that's not what I want).

So the problem here seems to be be triggering the download. 

I've tried this on firefox (running my app), and also on chromium (via 
minimal app just to reproduce this issue). 

I'm running web2py version 2.4.7

Also the most similar reported issue I've found in this list was:
https://groups.google.com/forum/#!topic/web2py/GH2HVCGPMKo

Because no answer was found then and I was unsure about this group's policy 
of reviving old threads, I published mine as a new question. Hope this is 
ok.









-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to