jquery submit form ajax 1

jquery submit form ajax

// jQuery ajax form submit example, runs when form is submitted
$("#myFormID").submit(function(e) {
    e.preventDefault(); // prevent actual form submit
    var form = $(this);
    var url = form.attr('action'); //get submit url [replace url here if desired]
         type: "POST",
         url: url,
         data: form.serialize(), // serializes form input
         success: function(data){

Here is what the above code is Doing:
1. Prevent the default form submit action
2. Get the form object
3. Get the form action url
4. Send the form data to the url via ajax
5. If successful, log the data to the console

Similar Posts