I want to perform an ajax request right before my form is submitted, and then trigger the form submission from my ajax callback. But when I try to trigger the submit, I get the following error:
Uncaught TypeError: Property 'submit' of object # is not a function
Here is the entire code:
<form id="myform" method="post" action="http://www.google.com" >
<input type="text" name="email" id="test" size="20" />
<input id="submit" name="submit" type="submit" value="Submit" />
</form>
<script>
function do_ajax() {
var jqxhr = $.get("#", function(){
// Once the ajax function is complete, I want to submit my form:
$('#myform').submit();
});
}
$(function() {
$('#submit').click(function (e) {
// When the user clicks submit, I want to perform an ajax request first:
e.preventDefault();
do_ajax();
});
});
</script>
Stumped.