I have a very ajax heavy website, its basically a SPA, but I wont label it that since it doesn't follow all the guidelines.
I have a store, which resides in a div on the page and its updated via jquery ajax and knockout. One of the final things I need is the ability to download pdf's from a third party web service. I am able to download the pdf using the following
<form action="/Dashboard/DownloadPdf" method="POST" style="display:none;" id="ProductDownload" data-bind="with: ProductToDownload">
<input type="hidden" id="Name" name="Name" data-bind="value: Name"/>
<input type="hidden" id="FileName" name="FileName" data-bind="value: FileName"/>
<input type="hidden" id="Id" name="Id" data-bind="value: Id"/>
<input type="hidden" id="Date" name="Date" data-bind="value: Date"/>
<input type="hidden" id="Number" name="Number" data-bind="value: Number"/>
</form>
And I use knockout to populate ProductToDownload before submitting the form.
$('form').submit();
What I want to be able to do is give the user some indication that an action is taking place and has finished, such as throwing up a loader while the form is being fetched.
My problem lies with the ability to know when the form.submit() as finished.
How can I know when my form submit has finished so I can clean up loaders and such.
Also below is the code I use to pull down the pdf, it would be great if someone would verify I am doing it correctly.
[HttpPost]
public void DownloadPdf(Product product)
{
var asr = Services.GetProduct(Token, product);
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("Content-Disposition","attachment; filename=" + product.FileName);
Response.ContentType = "application/pdf";
Response.BinaryWrite(asr.Payload.Pdf);
Response.End();
}
Keep in mind that we do not store the PDF's locally, we request them from another service.