Skip to content

Instantly share code, notes, and snippets.

@ChristopherDosin
Created February 18, 2018 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristopherDosin/565fd1f3c05f2277a974216ab0adb1d9 to your computer and use it in GitHub Desktop.
Save ChristopherDosin/565fd1f3c05f2277a974216ab0adb1d9 to your computer and use it in GitHub Desktop.
Send form with ajax
$('#id-form button[type=submit]').click(function(e){
e.preventDefault();
$(this).text('Einen moment...');
var form = jQuery(this).parents("form:first");
var dataString = form.serialize();
var formAction = form.attr('action');
$.ajax({
type: "POST",
url : formAction,
data : dataString,
success : function(data){
console.log(data);
},
error : function(data){
var errors = $.parseJSON(data.responseText);
console.log(errors);
}
},"json");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment