Skip to content

Instantly share code, notes, and snippets.

@scruwys
Created July 7, 2015 19:28
Show Gist options
  • Select an option

  • Save scruwys/8ada6f3b777b2bc9b7a2 to your computer and use it in GitHub Desktop.

Select an option

Save scruwys/8ada6f3b777b2bc9b7a2 to your computer and use it in GitHub Desktop.
dynamic ajax forms with jquery
$.fn.extend({
submitAsync: function(params) {
var method = $(this).attr('method');
var defaults = {
type : ( method === undefined ) ? 'POST' : method,
url : $(this).attr('action'),
data : $(this).serialize(),
dataType : 'json',
encode : true
};
var options = $.extend({}, params = params || {}, defaults);
return $.ajax(options);
}
});
$('form.async').on('submit', function(e) {
$(this).submitAsync().done(function(data) {
console.log(data);
});
e.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment