开发者

jquery download a file on callback

开发者 https://www.devze.com 2023-01-28 15:19 出处:网络
I have a php script that zips up a series of files after a user selects the开发者_运维百科m from a list. I\'m currently making an ajax call to this script, and am passing it a series of urls that shou

I have a php script that zips up a series of files after a user selects the开发者_运维百科m 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


Have you tried:

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

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


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.


Just do window.location = zipfileurl;.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消