jQuery AJAX submit form | How To Submit AJAX Forms with JQuery

Submit AJAX Forms with JQuery

// this is the id of the form
$("#idForm").submit(function(e) {

    e.preventDefault(); // avoid to execute the actual submit of the form.

    var form = $(this);
    var url = form.attr('action');
           type: "POST",
           url: url,
           data: form.serialize(), // serializes the form's elements.
           success: function(data)
               alert(data); // show response from the php script.


<form id="contactForm1" action="/your_url" method="post">
    <!-- Form input fields here (do not forget your name attributes). -->

<script type="text/javascript">
    var frm = $('#contactForm1');

    frm.submit(function (e) {


            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
                console.log('Submission was successful.');
            error: function (data) {
                console.log('An error occurred.');