Generating PDF report via AJAX call MVC

Posted by Self-Innovator under ASP.NET AJAX on 5/27/2016 | Points: 10 | Views : 4363 | Status : [Member] | Replies : 2
Hi all,

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.

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Bhuvanesh6 on: 7/16/2016 [Member] Starter | Points: 25

Up
0
Down
Have you tried using some of the PDF javascript libraries to render PDF directly from javascript without plugins, like mozilla pdf.js or jspdf.

Please reply with error what you face executing above code.

Bhuvan

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 7/11/2018 [Member] [MVP] Silver | Points: 25

Up
0
Down
You have only passed "selectedReport" in the data. You need to pass the "storeNumber" as parameter.

"/StoreProfile/PrintReports?selectedReport=" + $("#bindReports").val() + "&storeNumber =" + '@Model.StoreProfileAssociation.StoreNumber';


Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response