-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.ajaxifyForms.js
More file actions
24 lines (24 loc) · 948 Bytes
/
Copy pathjquery.ajaxifyForms.js
File metadata and controls
24 lines (24 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(function ($) {
$.fn.ajaxifyForms = function () {
/// <summary>Makes all non-ajaxy forms in a container ajaxy
/// This shouldn't be used if possible...</summary>
/// <returns type="Object">jquery deferred object</returns>
var def = new $.Deferred();
$(this).on('submit', 'form', function () {
var form = $(this),
result;
if (form.attr('method') != 'post') {
result = $.get(form.attr('action'), form.serialize());
} else {
result = $.post(form.attr('action'), form.serialize());
}
result.done(function (data, textStatus, jqXHR) {
def.resolve(data, textStatus, jqXHR);
}).fail(function (data, textStatus, jqXHR) {
def.reject(data, textStatus, jqXHR);
});
return false;
});
return def.promise();
};
})(jQuery);