Created
December 18, 2019 21:15
-
-
Save LouisdeBruijn/2a29aba347c741bac7528dd6386ce65d to your computer and use it in GitHub Desktop.
Catch user submit event and submit form via AJAX with FormData object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#contact-form-button').click(function(event){ | |
// Prevent redirection with AJAX for contact form | |
var form = $('#contact-form'); | |
var form_id = 'contact-form'; | |
var url = form.prop('action'); | |
var type = form.prop('method'); | |
var formData = getContactFormData(form_id); | |
// submit form via AJAX | |
send_form(form, form_id, url, type, modular_ajax, formData); | |
}); | |
function getContactFormData(form) { | |
// creates a FormData object and adds chips text | |
var formData = new FormData(document.getElementById(form)); | |
// for (var [key, value] of formData.entries()) { console.log('formData', key, value);} | |
return formData | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment