1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| (function($){
jQuery.fn.Ajax = function(options) {
options.ajax_url = (!options.ajax_url) ? '' : options.ajax_url;
var ajax_form = (!options.ajax_form) ? '' : $(options.ajax_form).serialize();
options.ajax_method = (!options.ajax_method) ? 'GET' : options.ajax_method;
options.ajax_dataType = (!options.ajax_dataType) ? 'json' : options.ajax_dataType;
options.ajax_parameters = (!options.ajax_parameters) ? '' : options.ajax_parameters;
options.redirect = (!options.redirect) ? false : options.redirect;
options.div_response = (!options.div_response) ? false : options.div_response;
options.loader = (!options.loader) ? false : options.loader;
if(options.loader) $(options.loader).show();
if(options.div_response) $(options.div_response).fadeOut('slow');
$.ajax({
type:options.ajax_method,
url:options.ajax_url,
dataType:options.ajax_dataType,
data:ajax_form + options.ajax_parameters,
complete:function() { if(options.loader) $(options.loader).hide(); },
success:function(datas){
if(datas != false && options.div_response){
$(options.div_response).html(datas);
$(options.div_response).fadeIn('slow');
}
else if(datas == false && options.redirect){
window.location.href = options.redirect;
}
else {
return false;
}
}
});
};
})(jQuery) |
Partager