Trigger a form submit from within an AJAX callback using jQuery

Posted by Yarin on Stack Overflow See other posts from Stack Overflow or by Yarin
Published on 2012-03-19T23:25:13Z Indexed on 2012/03/19 23:30 UTC
Read the original article Hit count: 296

Filed under:
|
|
|

I want to perform an ajax request right before my form is submitted. I want to trigger the form submit 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 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(){

            $('form').submit();

        });
    }

    $(function() {

        $('#submit').click(function (e) {

            e.preventDefault();
            do_ajax();

        });
    });

</script>

Stumped.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html