Last active
August 29, 2015 14:25
-
-
Save weirongxu/b4e9f4819cfa88be1a67 to your computer and use it in GitHub Desktop.
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
;(function($) { | |
$.fn.extend({ | |
ajaxForm: function(){ | |
var action = this.attr('action'); | |
var method = this.attr('method'); | |
var d = $.Deferred(); | |
this.on('submit', function(){ | |
fetch(action, { | |
method: method, | |
credentials: 'same-origin', | |
body: new FormData(this[0]), | |
}).then(function(data){ | |
d.resolve(data); | |
}).catch(function(data){ | |
d.reject(data); | |
}); | |
return false; | |
}); | |
return d.promise(); | |
}, | |
}); | |
})(jQuery); |
Author
weirongxu
commented
Jul 23, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment