L
L
Larisa .•º2017-03-17 16:09:33
Django
Larisa .•º, 2017-03-17 16:09:33

How to save a file (ajax request)?

ajax send a GET request to the server
then the server returns the xsl file, implementation :

response = HttpResponse(content_type='application/json')
        response['Content-Disposition'] = 'attachment; filename="team_maxes.xlsx"'
 
        wb = xlwt.Workbook()
          ....
        return response


and then on the client it is not possible to give this file to the user for downloading, I do this:
success: function (data) {
                        var bb = new Blob([data],{ type: 'application/vnd.ms-excel;charset=utf-8;',endings:'native'});                          
                         var bUrl = URL.createObjectURL(bb);
                         window.open(bUrl,"_self");
  }


A dialog box is shown to save the xsl file, but the data there is somehow unreadable. Excel says :
File format does not match file content !
Tell?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2017-03-17
@Astrohas

response = HttpResponse(содержимое_xls, content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename="foo.xls"'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question