1

I wonna download file using javascript or jquery. I have to send request using post, cause I am sending also some data for file generation.

Currently I have:

$.ajax(reportGenerateUrl + reportName,{
                    contentType : "application/pdf",
                    processData : false,
                    method : "POST",
                    headers : csrfHeaders(),
                    data: criteria,
                    success : function(data, status, jqHXR) {
                        alert('Report generated!');

                    },
                    error : function(jqXHR, textStatus, errorThrown, data) {
                        alert('Unable to get report!');

                    }
                });

My server returns pdf file, but no download prompt. I am getting file ooutput in network page in chrome dev tools.

Can any one help?

Kamil Piwowarski
  • 506
  • 5
  • 15
masterdany88
  • 5,041
  • 11
  • 58
  • 132
  • you can create HTML hidden form through java script and then use `form.submit()` on it – Bilal Zafar Apr 27 '18 at 11:25
  • @Arvind this is not true. You just have to handle the disposition yourself. Related: https://stackoverflow.com/a/23797348/4108884 – Samuil Petrov Apr 27 '18 at 11:27
  • Possible duplicate of [Prompt file download](https://stackoverflow.com/questions/40662885/prompt-file-download) – AxelH Apr 27 '18 at 11:27

0 Answers0