I am encountering an issue with my code that is triggered by the "export" li tag. It converts a FusionChart to an SVG string and then sends it to my controller via an ajax call.
The problem I'm facing is that even though the controller receives the request, processes it successfully till the end, and displays "Success" in an alert message, the popup to save the PDF does not appear.
Interestingly, when I copy the entire HTML string, paste it into notepad, save it as an HTML file, everything works as expected. However, it fails to function properly when running from the controller and trying to display the save prompt...
Could there be something I'm overlooking? Or perhaps I'm doing something incorrectly or not following best practices?
Here's the section of code that invokes a JavaScript function:
<li id="export" style="font-size:13px"><a onclick="svgString()">Rotativa Export</a></li>
Below is the JavaScript code responsible for making the AJAX call:
function svgString() {
var ChartSVG = new Array(10);
var text = document.createTextNode(savingsChart.getSVGString());
document.getElementById("msg").appendChild(text);
ChartSVG = chunkSubstr(document.getElementById("msg").innerHTML, 10);
var Details = {
"fkiProjectID": @Model.fkiProjectID,
"ChartSVG": ChartSVG
};
$.ajax({
url: '/Profile/ExportCombinedPDF',
data: JSON.stringify(Details),
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert("Success : " + data);
},
error: function(data) {
alert("Error: " + data);
}
});
}
document.getElementById("export").addEventListener("click", svgString);
function chunkSubstr(str, size) {
var numChunks = Math.ceil(str.length / size),
chunks = new Array(size);
for (var i = 0, o = 0; i < size; ++i, o += numChunks) {
chunks[i] = str.substring(o, o + numChunks);
}
return chunks;
}
Controller:
public FileStreamResult ExportCombinedPDF(CalculatedOutputViewModel CVM) {
// Controller logic goes here...
}
If anyone can provide insight or assistance on this matter, it would be greatly appreciated! Thank you!