Wednesday, February 22, 2012

Download onClick

Ajax requests to server are always expected to return text output and for some reason the
Content-disposition: attachment;
doesn't cause the browser to show the save dialog. I searched for a while and found a jquery plugin which does it but i kept looking anyway. One interesting solution was to include an iframe in the page and set its' location to the url which would download the file when that didn't work i just used the
var url = "cgi-bin/" + $.params({qo:"LDS", sv:["dk", "df"]});
window.location = url
And surprisingly this worked well atleast on the browsers that i checked with.. (chrome, ff ).

No comments: