userimage
Moe

how to submit a form using ajax call

I have a form:

<form id="myform" method="post" action="/myformsubmit">
    <div class="form-group">
        <label for="username" class="control-label">Id</label> <input
            type="text" class="form-control" id="usernameLogin"
            name="username" value="${LOGIN_ID}" required
            title="Please enter you user id"
            autocomplete="off"> <span
            class="help-block"></span>
    </div>
    <div class="form-group">
        <label for="password" class="control-label">Password</label> <input
            type="password" class="form-control" id="passwordLogin"
            name="password" value="" required
            title="Please enter your password" autocomplete="off">
    </div>
    <button type="button" class="btn btn-block loginBtn"
        id="loginFormButton">Login</button>
    <br />
    <div class="row">
        <div class="col-sm-6 frgtPass">
            <a href="#" data-dismiss="modal" data-toggle="modal"
                data-target="#forgotModal">Forgot password?</a>
        </div>
        <div class="col-sm-6 newSignup">
            New here? <a href="#" data-dismiss="modal" data-toggle="modal"
                data-target="#signUpModal">SIGNUP</a>
        </div>
    </div>
</form>

i want to submit this form using ajax by preventing default submit of this form.

userimage

To submit the mentioned form you can use below process:


$(function() {
    $("#myform").on('click', function(e) {
        e.preventDefault();
        var id = $('#usernameLogin').val();
        var password = $('#passwordLogin').val();
            // Do required action and then submit form as below mentioned
            $("#myform").submit();
    });
});


Hope this will resolve your problem.

Answer is