Skip to content

Instantly share code, notes, and snippets.

@gcphost
Created June 28, 2015 03:20
Show Gist options
  • Save gcphost/448a9fe398604b0f7b81 to your computer and use it in GitHub Desktop.
Save gcphost/448a9fe398604b0f7b81 to your computer and use it in GitHub Desktop.
jQuery JSON Form Post
# As-seen-at https://asked.io/jquery-json-post-form-data
$.fn.postJson = function(success) {
return this.each(function() {
$(this).on('submit', function(){
$.post( $(this).data('action'), $(this).serialize(), success, "json");
return false;
});
});
};
$('form').postJson(function( data ) {
console.log(data)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment