Upload a file using Javascript via POST

I am currently using this solution to download excel files using javascript. When the user clicks the button, my javascript creates the url that I load with iframe. This solution works for short URLs. However, I came across a case where my URL is too long for the request get. I would like to keep the same behavior so that new windows do not open for excel export. However, it would be nice to open a time window if necessary. I was thinking of one solution that I would like to avoid:

  • Make a request POSTthat creates the excel file, saves it to a temporary folder, and returns a unique file name.
  • Request the file name in the url created for the iframe.

I do not like this solution because it requires a non-trivial amount of work to set up a temporary folder that will be used on all our web servers. Also, I just wouldn't want to create a temporary file if I don't need it.

current code:

$("body").append('<iframe width="0" height="0" frameborder="0" src="' + dynamicallyCreatedUrl + '"></iframe>');

Is there a way to make a request POSTto download an excel file using javascript?

This solution should work for IE8 +, Firefox, Chrome. Just for reference: I am using IIS7, ASP.Net MVC, C #. I have access to YUIand JQuery.

+4
source share
1 answer

, POST, .

API- URL-. , URL- URL-.

, :

tinyurl, , javascript , , GET URL- .

JavaScript JavaScript, ,

+1

All Articles