jquery下载回调文件。

时间:2023-02-06 00:19:42

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?

我有一个php脚本,在用户从列表中选择一系列文件后,它会对这些文件进行压缩。我目前正在对这个脚本进行ajax调用,并向它传递一系列应该压缩的url。我希望这个zip文件在它完成压缩后自动下载,并且在计算如何做到这一点上有困难。如果我将php文件中的zip url传递回js文件,那么在zip文件完成后强制下载该文件的最佳方式是什么?

Thanks

谢谢

3 个解决方案

#1


4  

Have you tried:

你有试过:

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

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

假定响应是文件名作为字符串。

#2


1  

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.

浏览器将尝试切换到所提供的URL,识别它不是一个网页,停留在旧的页面并下载zipfile。

#3


0  

Just do window.location = zipfileurl;.

只做窗口。位置= zipfileurl;。

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

浏览器会知道它不能打开zip文件,所以会下载它。

#1


4  

Have you tried:

你有试过:

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

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

假定响应是文件名作为字符串。

#2


1  

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.

浏览器将尝试切换到所提供的URL,识别它不是一个网页,停留在旧的页面并下载zipfile。

#3


0  

Just do window.location = zipfileurl;.

只做窗口。位置= zipfileurl;。

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

浏览器会知道它不能打开zip文件,所以会下载它。