0

I wanted to Generate a PDF report using Ajax call, I can able to generate it successfully with below statement but how can ii achieve this using AJAX call

 $('#printReports').click(function () {
     window.location.href = "/StoreProfile/PrintReports?selectedReport=" + $("#bindReports").val() + "&storeNumber=" + '@Model.StoreProfileAssociation.StoreNumber';
}

Instead of above statement i want it to generate PDF using AJAX, the below code i have tried but seems does not working, kindly help me with some good suggestions

$('#printReports').click(function () {                 
            $.ajax(
                   {
                       type: 'GET',
                       data: { 'selectedReport': selectedReport },
                       datatype: "json",
                       url: "/StoreProfile/PrintReports",
                       success: function (data) {
                           var json = data;
                           console.log(json);
                           //$('#printReports').html('');
                           //$('#_genericReport').html(data);
                           window.location.href = "/StoreProfile/PrintReports";
                       },
                       error: function (result) {
                           showAlert("Error", 'Failed to load the result');
                       }
                   })
  I tried in the above method but didn't worked.
Sayeed
  • 1
  • 1
  • I think file downloads are not possible with AJAX calls. You can just use `window.location="/download/StoreProfile/PrintReports?filename=report.xls";` – Lucky May 27 '16 at 11:20
  • Actually i have to generate the PDF report on the same page. then i'll be sending it to printer. Is any other way to achieve using ONLY AJAX CALLS – Sayeed May 27 '16 at 11:58
  • Please refer http://stackoverflow.com/a/20830337/1793718. You can just use `window.location="/download/StoreProfile/PrintReports?filename=report.xls";` – Lucky May 27 '16 at 11:59
  • I have tried this way but it didn't generating the PDF file success: $.ajax( { type: 'POST', data: { 'selectedReport': selectedReport, 'storeNumber' :storeNumber}, datatype: "json", url: "/StoreProfile/PrintReports",function (data) { var json = data; console.log(json); window.location = "/StoreProfile/Index";} – Sayeed May 27 '16 at 13:07

0 Answers0