简体   繁体   中英

unable to download excel file using ajax jquery

I have

$.ajax({
   url: 'service url',
   type: 'POST',
   async : true,
   contentType: false,
   processData: false,
   cache: false,
   success: function(data){

   },
   error: function(err){}
});

I can see the file in my Content-disposition in the chrome inspector and the response shows an encrypted value in the inspector.

However, no file is being downloaded. What is missing here?

Content-Disposition will influence what happens when you load a resource in a browser window.

It doesn't do anything when you are handling the response manually with JavaScript.

If you want to trigger a download from that point, you'd need to handle the response, generate a data: scheme URI and set location to it.

It would be simpler to submit a form to the destination URL in the first place (unless you don't need POST in which case you can just set location to it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM