Created
December 27, 2011 21:20
-
-
Save ka8725/1525200 to your computer and use it in GitHub Desktop.
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
$.fn.submitWithAjax = function(params) { | |
var options = { | |
type : this.attr('method') || 'POST', | |
url : this.attr("action"), | |
data : this.serialize(), | |
callbacks : {}, | |
target : '#temp', | |
freezing : this, | |
dataType : 'script', | |
autoActivate : true | |
}; | |
$.extend(options, params); | |
var loader_id = $.AjaxLoader.on(options.freezing); | |
$.ajax({ | |
type: options.type, | |
url: options.url, | |
data: options.data, | |
success: function(data, textStatus, XMLHttpRequest) { | |
if (options.autoActivate || (data.code != 0)) { $.AjaxLoader.off(loader_id, 0); } | |
if (options.callbacks.success) { options.callbacks.success(data, textStatus, XMLHttpRequest); } | |
}, | |
error: function(jqXHR, textStatus, errorThrown) { | |
if (options.callbacks.error) { | |
$.AjaxLoader.off(loader_id); | |
options.callbacks.error(jqXHR, textStatus, errorThrown); | |
} else { | |
$.AjaxLoader.off(loader_id,1); | |
} | |
}, | |
dataType: options.dataType | |
}); | |
return false; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment