I'm creating a form tag and submit it with certain data, to download a file without reloading the entire page.
Form tag is made invisible and appended to the body element.
var frm = $('<form />');
frm.attr('method', 'POST');
frm.attr('action', url);
frm.attr('display', 'none');
$(document.body).append(frm);
frm.submit();
Everything works fine, except that after some time I see these invisible forms accumulating in the body element, even after their work is done, wasting memory.
How can I programmatically detect that form's work is done, and destroy the form element?
I understand that I can use a timeout with a reasonable delay to do this, but need to know if there is a better way? Perhaps by using a IFRAME?