Last active
November 30, 2019 20:40
-
-
Save Shivabeach/5074369 to your computer and use it in GitHub Desktop.
ajax form one size fits all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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