下载为响应$ .ajax

时间:2018-02-06 07:56:09

标签: jquery ajax excel

$ .ajax返回整个excel文件作为响应。我尝试了所有可能的下载方法,但无法正确获取excel。以下是我的代码段。

             df$.ajax({
                        url : "myUrl",
                        type: "POST",
                        data : {
                            method : 'exportLanguageTranslationFile',
                            requestJSON: requestJSON,
                            dataType: 'json',
                            responseType: 'file'
                        },
                        dataType: 'text',
                        async : false,
                        success:function(response){
                          var a  = df$('<a class="downloadFile"></a>')
                            .hide()
                            .attr({ download : "test-file.xlsx" , href : window.URL.createObjectURL(new Blob(binaryData, {type: "application/octet-stream"}))});
                            df$('#fieldDialogData').append(a);
                            df$('.downloadFile').click();

                       }
                  });

我也可以下载excel文件,但它说文件格式错误或已损坏。作为回应&#34;内容类型&#34; of file是&#34; application / octet-stream&#34;和文件是.xlsx格式。

0 个答案:

没有答案