Last Updated: September 29, 2021
·
7.337K
· dizpers

AJAX form submit with jQuery

Method 1

$.get('server.php?' + $('#theForm').serialize())

$.post('server.php', $('#theForm').serialize())

Method 2

With use of jQuery form plugin.

Send when the "Submit" button is pressed:

$("#theForm").ajaxForm({url: 'server.php', type: 'post'})

Send immediately:

$("#theForm").ajaxSubmit({url: 'server.php', type: 'post'})

Based on this SO answer.

1 Response
Add your response

Method 3

$('form').on('submit', function() {

    var $form = $(this);

    $.post( $form.attr('action'), $form.serialize(), function(response) {

        var response = $.parseJSON(response);

        console.log("Response: ", response);

    });

    return false;

});
over 1 year ago ·