Previously achieved export Excel, the form is submitted in form, because the package jquery ajax request to export Excel, the browser does not display the file.
But this needs to be with a header, form can not take the form header, the next Baidu, native ajax support binary data format of the exported Excel.
1, JS method where all the code
// native Ajax var = new new XHR the XMLHttpRequest (); path // POST mode request background xhr.open ( 'POST', '/ API / Export', to true); // Excel derived binary data type, provided as BLOB xhr.responseType = 'BLOB'; // request header (key, value), the first request may be provided a plurality of key-value pairs xhr.setRequestHeader ( 'Content-Type', 'application / json; charset = utf-8 '); // returns successful, the exported Excel file xhr.onload = function () { IF (== 200 is this.status) { var = this.response BLOB; var a = document.createElement (' a '); var = window.URL.createObjectURL URL (BLOB); a.href = URL; // set the file name a.download = 'Excel file name .xlsx'; a.click (); } } var feeDate = $ ( '# feeDate ') .val (); // parameters of the request, json format, use the background json format received xhr.send (the JSON.stringify ({ "feeDate": feeDate }));
form export forms Excel, please refer to
https://www.cnblogs.com/Donnnnnn/p/7902718.html