These two snippets of code may seem similar in function, but they actually behave differently:
window.location = "../PlanView/ExportAsPDF";
$.ajax({
url: '../PlanView/ExportAsPDF',
data: { },
success: function (stream) { window.location = stream; }
});
The first block of code initiates a download for a .PDF file while the second one does not, resulting in an unusual request appearing in my browser's network traffic.
If anyone could point out the key distinctions between these two approaches, I would greatly appreciate it.
A more detailed explanation is as follows:
I am required to transmit a larger amount of data to my server than what can be accommodated in a URL. Consequently, I need to send the data via POST rather than GET. The former code is unsuitable for this purpose due to the limitation on URL length - causing the server to return a 414 error.
I aim to achieve the same functionality as the first code snippet using the second one.
public ActionResult ExportAsPDF(string dataURL)
{
Document document = new Document(PageSize.A4.Rotate(), 15, 15, 30, 65);
byte[] buffer = new byte[0];
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter.GetInstance(document, memoryStream);
document.Open();
document.Add(new Paragraph("First PDF file"));
document.Close();
buffer = memoryStream.ToArray();
}
return File(buffer, "application/pdf", "PlanView.pdf");
}