fileDownload.jsを使う.
http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax
fileDownloadのCDN(?)
http://jqueryfiledownload.apphb.com/Scripts/jquery.fileDownload.js
jQueryを事後的に読む(DOMに追加)
var head= document.getElementsByTagName('head')[0]; var script= document.createElement('script'); script.type= 'text/javascript'; script.src= 'https://code.jquery.com/jquery-2.1.1.min.js'; head.appendChild(script);
jQueryのgetScriptで読み込む
$.getScript("http://jqueryfiledownload.apphb.com/Scripts/jquery.fileDownload.js")
fileのダウンロード
http://jqueryfiledownload.apphb.com/
$.fileDownload('some/file.pdf')
うまくいかない
別の方法
http://filamentgroup.com/lab/jquery-plugin-for-requesting-ajax-like-file-downloads.html
jQuery.download = function(url, data, method){ //url and data options required if( url && data ){ //data can be string of parameters or array/object data = typeof data == 'string' ? data : jQuery.param(data); //split params into form inputs var inputs = ''; jQuery.each(data.split('&'), function(){ var pair = this.split('='); inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; }); //send request jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>') .appendTo('body').submit().remove(); }; }; $.download('http://ai.yimg.jp/c/logo/f/2.0/news_r_34_2x.png','filename=hoge&format=png);
Yahooは拒否ってるっぽい