12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //重写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
- });
- };
- })($);
- $.fn.extend({
- submitWithLoading: function () {
- var $loading = $('#loading');
-
- $loading.show();
- $(this).submit();
- }
- });
|