Skip to content

Instantly share code, notes, and snippets.

@NathanielWroblewski
Created November 4, 2014 21:57
Show Gist options
  • Save NathanielWroblewski/8103af631fde7c8414ff to your computer and use it in GitHub Desktop.
Save NathanielWroblewski/8103af631fde7c8414ff to your computer and use it in GitHub Desktop.
Ajax Post on Form Submit
// execute code once the page has loaded
$(document).ready(function() {
// listen for the form being submitted
$('form').on('submit', function(e) {
// prevent the actual form submission
e.preventDefault()
// redirect the form data ($(this).serialize) through AJAX to some api endpoint (/some-api-endpoint)
$.post('/some-api-endpoint', $(this).serialize(), function(response) {
// log the JSON response to your console after you drop a BOOM
console.log('BOOM', response)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment