I have a question related to the file downloading using POST.
I have the following javascript which sends a POST request to the server side to download a file:
function postCall(url, params) {
function doPostCall() {
var newForm = jQuery('<form>', {
'method':'POST',
'action': url
});
for(key in params) {
if (params.hasOwnProperty(key)) {
newForm.append(jQuery('<input>', {
'name': key,
'value': params[key],
'type': 'hidden'
}));
}
}
newForm.appendTo("body").submit();
}
This method is called from an invisible iframe from the HTML page. This page also has another normal GET request to get a static HTML. However, every time the above method is called, The call to get the static page never returns from the server side.
I know it is a little hard to understand with such little information, but the code are huge and hard to be put here. My question is that:
- Is there any obvious problem with the above code which uses an invisible form to send a POST request to get file?
- Is there any other better way to send a POST request to the server to download file. (People told that Ajax calls cannot be used to download file)?
- If this code is OK and no other way is available. Is there anyway to force this method to be run at the last thing after the whole page is loaded and all other requests are completed?