Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery download a file on callback

I have a php script that zips up a series of files after a user selects them from a list. I'm currently making an ajax call to this script, and am passing it a series of urls that should be zipped. I would for this zip file to be downloaded automatically when its finished being zipped, and am having trouble figuring out how to do this. What would be the best way to force download this zip file after its finished, assuming i'm passing the url of the zip from my php file back to my js file?

Thanks

like image 262
minimalpop Avatar asked Dec 03 '10 22:12

minimalpop


2 Answers

Have you tried:

success: function(resp) {
    window.location.href = resp;
}

That assumes that the response is the filename as a string.

like image 193
karim79 Avatar answered Oct 22 '22 09:10

karim79


window.location=zipfilePath;

The browser will try to switch to the provided URL, recognize that it's not a webpage, stay on the old page and download the zipfile.

like image 39
thejh Avatar answered Oct 22 '22 09:10

thejh