1

I need to export tables from database to generate a Excel file so the user can download. I am currently using the plain form submit with hidden iframe, and the endpoint generates a response that contains Content-Disposition.

But, I need to display a message to user if server is fails to generate excel file is or any Server-side Error / Exception occurs.

I switched to use Jquery form plugin. While it does give me the response body, but it won't trigger the Save.

Are there any other alternatives to it ?

Tapas Thakkar
  • 845
  • 8
  • 19
  • What backend are you using? You should probably do this with an AJAX call instead... – Milney Apr 21 '17 at 09:31
  • WCF (C#) i have tried ajax call, it gives the callback for success and error both but doesn't download the file. @Milney – Tapas Thakkar Apr 21 '17 at 09:50
  • 1
    You can try this way: http://stackoverflow.com/questions/16086162/handle-file-download-from-ajax-post – Milney Apr 21 '17 at 10:01
  • i have tried that @Milney bro.. but it's not a good solution, it takes the twice of time than simple form submit, because it will fire a same proxy twice, first to check whether it succeed or not and another one for file download. – Tapas Thakkar Apr 21 '17 at 10:12

2 Answers2

1

After trying jQuery, Ajax and lot.. finally got an proper solution.

jQuery ajax is not able to handle binary responses properly (can't set responseType), so it's better to use a plain XMLHttpRequest call

Here is The Answer :-)

Community
  • 1
  • 1
Tapas Thakkar
  • 845
  • 8
  • 19
0

use jQuery.fileDownload.js

$.fileDownload(url,{
                    httpMethod: 'get',
                    data:$("#"+formId).serialize(),
                    prepareCallback:function(url){

                    },
                    successCallback:function(url){

                    },
                    failCallback: function (html, url) {

                    }
                 });

and server side add response.setHeader("Set-Cookie", "fileDownload=true; path=/");

Janet Wu
  • 516
  • 4
  • 3