Skip to content

Instantly share code, notes, and snippets.

@Shivabeach
Last active November 30, 2019 20:40
Show Gist options
  • Save Shivabeach/5074369 to your computer and use it in GitHub Desktop.
Save Shivabeach/5074369 to your computer and use it in GitHub Desktop.
ajax form one size fits all
#ajax can be any form ID or class name. I just use ajax
$('form#ajax').on('submit', function(){
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(responce){
$('#display').html(response).delay(6000).fadeOut(1000);
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment