これは、独自の引数を追加する関数であり、get メソッドも更新します。しかし、ご覧のとおり、 $.ajax をラップしているだけです
(jQuery ソースから直接取得)
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
// shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
return jQuery.ajax({
type: method,
url: url,
data: data,
success: callback,
dataType: type
});
};
});
編集 - 変更されたコードの例 すべての引数が必要です
jQuery.each( [ "myPost" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type, errorCallback ) {
return jQuery.ajax({
type: method,
url: url,
data: data,
success: callback,
dataType: type,
error: errorCallback
});
};
});