jquery 拦截 post 等请求实现aop效果
$(function(){jQuery.extend({put: function( url, data, callback, type ) {// shift arguments if data argument was omitedif ( jQuery.isFunction( data ) ) {type = type || callback;callback = data;data = {};}return jQuery.ajax({type: "PUT",url: url,data: data,success: callback,dataType: type});},del: function( url, data, callback, type ) {// shift arguments if data argument was omitedif ( jQuery.isFunction( data ) ) {type = type || callback;callback = data;data = {};}return jQuery.ajax({type: "DELETE",url: url,data: data,success: callback,dataType: type});}})jQuery.each( [ "get", "post","put","del"], function( i, method ) {// jQuery.get或jQuery.post为jQuery[ method ] = function( url, data, callback, type ) {if($("#loading")){$("#loading").show()}var callbackafter = function(){if($("#loading")){$("#loading").hide()}callback.call(window,arguments[0]);}// 模拟重载if ( jQuery.isFunction( data ) ) {type = type || callback;callback = data;data = undefined;}// 利用jQuery.ajax完成任务return jQuery.ajax({url: url,type: method,dataType: type,data: data,success: callbackafter});};});})()function disableAop(){jQuery.each( [ "get", "post","put","del"], function( i, method ) {// jQuery.get或jQuery.post为jQuery[ method ] = function( url, data, callback, type ) {// 模拟重载if ( jQuery.isFunction( data ) ) {type = type || callback;callback = data;data = undefined;}// 利用jQuery.ajax完成任务return jQuery.ajax({url: url,type: method,dataType: type,data: data,success: callback});};});}
拦截就是重写jquery默认的post等方法
还有一个禁用aop的就是把源码再声明一遍即可
浙公网安备 33010602011771号