Take the 2-minute tour ×

I have a CSV at my server but when I do Ajax, it just shows in my "Network" in Google Chrome when I "Inspect element".

Code is here:

            method: 'POST',
            headers: {
                "Content-type": "text/csv",
                'Content-Disposition': 'attachment'
            url: 'php/files/' + tabid + '.csv'

What do I need to add to get my browser download a file on my local machine? Thank you! :)

Ext-JS 4, CakePHP 2.2.5

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You cannot start download using XHR request. But there are at least two ways how you can do it:

  • If the file-path is fix an you know it set top.location.href = "YourPath"; within the success handler of the ajax call. top.location.href
  • If you create the file and want to return it you should create a hidden iframe and inject a form into it that then execute the request.
share|improve this answer
I know the location and the file so I'll try top.location.href. Thank you. :) –  user1509885 Jan 30 '13 at 8:51
I've spent a whole day trying this with Ext.Ajax and I've just needed a 1 line, and it's not even from Ext-JS? xD I hate you, JavaScript, I hate you. xD Thank you, sra. It works. –  user1509885 Jan 30 '13 at 8:59
@user1509885 You're welcome ;) –  sra Jan 30 '13 at 9:00
add comment

Your Answer

