Created
July 7, 2015 19:28
-
-
Save scruwys/8ada6f3b777b2bc9b7a2 to your computer and use it in GitHub Desktop.
dynamic ajax forms with jquery
This file contains hidden or 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
| $.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