Ajax is not able to download files directly, so it is generally done by a hyperlink to download a file
But when it comes to the need to send a lot of data to the server to download again, the form of hyperlinks is a bit bad to see,
/*=================== Download file * options:{* URL: ', //* Data:{name:value},//data to be sent * method: ' Post ' *} */var Downloadfil E = function (options) { var config = $.extend (True, {method: ' Post '}, options); var $iframe = $ (' <iframe id= "down-file-iframe"/> '); var $form = $ (' <form target= "down-file-iframe" method= "' + Config.method + '"/> '); $form. attr (' action ', config.url); for (var key in Config.data) { $form. Append (' <input type= "hidden" name= "' + key + '" value= "' + Config.data[key] + '/> '); } $iframe. Append ($form); $ (document.body). Append ($iframe); $form [0].submit (); $iframe. Remove ();
Leave it for backup.
Ajax post-submission method download file processing (GO)