$(function(){
jQuery.extend({
put: function( url, data, callback, type ) {
// shift arguments if data argument was omited
if ( 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 omited
if ( 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的就是把源碼再聲明一遍即可