The Ajax jquery form does not work

advertisements

I have a php file which imports the jquery.form.js file:

<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="createuser.js"></script>

createuser.js file:

$(document).ready(function()
{
    $("#UserButton").click(function()
    {
        alert("Here1");
        var ID = $("#ID").val();
        $("#User_Form").ajaxForm
        ({

            type: 'POST',
            url: 'createuser.php',
            data: {ID:ID},
            cache: false,
            error: function(data)
            {
                bootbox.dialog
                ({
                    alert("error");
                });
            },
            success: function(data)
            {

                if(data==0)
                {
                    alert("user created");

                }

            }
        }).submit();
    });

});

the createuser.js works till the first alert message i.e. Here1 but does not proceed further. the php script createuser.php works fine in isolation and returns 0. So there doesn't seem to be a problem with the createuser.php file.

Please let me know if i'm missing out on something.

thanks.


If you look in the console you will see an error saying that ajaxForm is not a function.

<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>

First you load a script which attempt to bind ajaxForm to the jQuery object. This fails.

Then you load jQuery.

You need to reverse the order you load those two scripts in.


It seems very strange to call ajaxForm in response to a click. Normally you would rant to call it in a ready handler so it would run when a regular submit button was clicked.