minimalpop
minimalpop

Reputation: 7058

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

Upvotes: 5

Views: 1803

Answers (3)

karim79
karim79

Reputation: 342625

Have you tried:

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

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

Upvotes: 4

Skilldrick
Skilldrick

Reputation: 70819

Just do window.location = zipfileurl;.

The browser will know that it can't open zip files, so will download it.

Upvotes: 0

thejh
thejh

Reputation: 45568

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.

Upvotes: 1

Related Questions