Skip to content

Instantly share code, notes, and snippets.

@mrpatg
Created May 19, 2017 00:30
Show Gist options
  • Select an option

  • Save mrpatg/bf2dbd9717e8e07a50c48d5c397361dc to your computer and use it in GitHub Desktop.

Select an option

Save mrpatg/bf2dbd9717e8e07a50c48d5c397361dc to your computer and use it in GitHub Desktop.
jquery submit form pt2
$('#create').submit(function() { // stop the form's submit event
$.ajax({ // create a new AJAX call
data: $(this).serialize(), // grab all values/data from the form and prep it
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to request, can be local or remote
success: function(response) { // on success
$('#results').html(response); // update the contents of the element.
}
});
return false; // cancel original event to prevent form submitting
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment