开发者

download file from ajax

开发者 https://www.devze.com 2023-03-05 05:38 出处:网络
I\'m setting up some htm开发者_Python百科l exporting to excel and is doing this via jquery $.post. The result is data

I'm setting up some htm开发者_Python百科l exporting to excel and is doing this via jquery $.post. The result is data

$.post('/exportToExcel.php', function(data) {    
    // data is the file i want to download now... how to trigger it?
});

data is the returned value (the file) from the server, simply doing alert(data) will output a bigger window full of lol. how to i trigger so the file is able to be download?


You cannot do that using Ajax. Load the file in an iframe, and send this HTTP header with the file:

Content-Disposition: attachment
0

精彩评论

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