I am unable to get jQuery's .submit() to work in IE or Firefox when I pass the form as text for the jQuery object.
For example, the following code works in Chrome and Safari, but in IE and Firefox nothing happens--no errors, no nothing:
$('<form id="frm" action="http://www.stackoverflow.com" method="POST"></form>')
.submit();
NOTE: "http://www.stackoverflow.com" above and the empty form is just an example. In my application, my form has a legitimate URL for "action=" that accepts POST data that I specify as hidden controls within the dynamically constructed form.
If I instead load the constructed form into an element in the html and then execute $('#frm').submit()
, it works; however, I would rather not go that route.
Is this known/expected behavior or am I doing something wrong?
~ ~ ~
In response to @DavidThomas, I am constructing the <form>
via a .get() call to a ASP .NET .ashx handler. I am attempting to minimize exposure to the <form>
and it's contents.
$.get('./ConstructForm.ashx', function (data) { $(data).submit(); })
.fail(function () { alert('fail!'); });
I certainly welcome recommendations for a more secure way to do this, but that would probably be a subject for a different question.
~ ~ ~
For what it's worth, my approach was initially based on this: https://stackoverflow.com/a/2054741/1530187
I am attempting to do this using a constructed string for the jQuery object, instead of an existing element, in an effort to minimize the user's ability to inspect the form prior to submit or after submit via the browser back.