Clients submit post requests using jquery ajax as illustrated below:
$.ajax({
url: \"/xxx?request1\",
data: theParams,
type: \'post\',
error
Content-Disposition: attachment
is the right header, but the browser only obeys it when loading the file directly.
Using AJAX (even through jQuery) will not work.
There is a way to do this.
Read the full explanation in this answer, but basically you just have to write that in your success
function:
window.location = "data:application/octet-stream," + encodeURIComponent(theResult);
Edit: FileSaver.js provides a wrapper improving browser compatibility and adding support for filenames for compatible browsers:
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");