//重写ajax,post增加loading (function ($) { var _ajax = $.ajax; $.ajaxWithLoading = function (opt) { var fn = { error: function (XMLHttpRequest, textStatus, errorThrown) { }, success: function (data, textStatus) { } }; if (opt.error) { fn.error = opt.error; } if (opt.success) { fn.success = opt.success; } var $loading = $('#loading'); var _opt = $.extend(opt, { error: function (XMLHttpRequest, textStatus, errorThrown) { $loading.hide(); fn.error(XMLHttpRequest, textStatus, errorThrown); }, success: function (data, textStatus) { $loading.hide(); fn.success(data, textStatus); } }); $loading.show(); $.ajax(_opt); }; $.getWithLoading = function (url, data, callback, type) { return $.ajaxWithLoading({ url: url, type: 'get', dataType: type, data: data, success: callback }); }; $.postWithLoading = function (url, data, callback, type) { return $.ajaxWithLoading({ url: url, type: 'post', dataType: type, data: data, success: callback }); }; })($);