2017  Kodetalk | Feedback | Privacy Policy | Terms | About

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
    <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">
    <button type="button" class="btn btn-block loginBtn"
    <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 class="col-sm-6 newSignup">
            New here? <a href="#" data-dismiss="modal" data-toggle="modal"

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


To submit the mentioned form you can use below process:

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

Hope this will resolve your problem.

Answer is