Skip to content

Instantly share code, notes, and snippets.

@imvarunkmr
Last active April 2, 2017 14:10
Show Gist options
  • Save imvarunkmr/3dac524c43943e03939651fbb83ccee4 to your computer and use it in GitHub Desktop.
Save imvarunkmr/3dac524c43943e03939651fbb83ccee4 to your computer and use it in GitHub Desktop.
Processing an ajax form using jQuery
$('form').submit(function(e) {
// get the form data
formData = $(this).serialize();
formData += '&action=submit_contact_form';
// process the form
$.ajax({
type : 'post',
url : localData.ajax_url,
data : formData,
dataType : 'json'
}).done(function(data) {
// use the data
console.log(data);
});
// Prevent the default click action
e.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment