mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
WETness getting you down? Fear not, the $.get and $.post methods are now 866% DRYer. This fixes #7847.
This commit is contained in:
parent
52b1709b94
commit
1830db4226
29
src/ajax.js
29
src/ajax.js
@ -113,9 +113,8 @@ jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".sp
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.extend({
|
jQuery.each( [ "GET", "POST" ], function( i, method ) {
|
||||||
|
jQuery[ method.toLowerCase() ] = function( url, data, callback, type ) {
|
||||||
get: function( url, data, callback, type ) {
|
|
||||||
// shift arguments if data argument was omited
|
// shift arguments if data argument was omited
|
||||||
if ( jQuery.isFunction( data ) ) {
|
if ( jQuery.isFunction( data ) ) {
|
||||||
type = type || callback;
|
type = type || callback;
|
||||||
@ -124,13 +123,16 @@ jQuery.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.ajax({
|
return jQuery.ajax({
|
||||||
type: "GET",
|
type: method,
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
success: callback,
|
success: callback,
|
||||||
dataType: type
|
dataType: type
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
jQuery.extend({
|
||||||
|
|
||||||
getScript: function( url, callback ) {
|
getScript: function( url, callback ) {
|
||||||
return jQuery.get(url, null, callback, "script");
|
return jQuery.get(url, null, callback, "script");
|
||||||
@ -140,23 +142,6 @@ jQuery.extend({
|
|||||||
return jQuery.get(url, data, callback, "json");
|
return jQuery.get(url, data, callback, "json");
|
||||||
},
|
},
|
||||||
|
|
||||||
post: 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: "POST",
|
|
||||||
url: url,
|
|
||||||
data: data,
|
|
||||||
success: callback,
|
|
||||||
dataType: type
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
ajaxSetup: function( settings ) {
|
ajaxSetup: function( settings ) {
|
||||||
jQuery.extend( jQuery.ajaxSettings, settings );
|
jQuery.extend( jQuery.ajaxSettings, settings );
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user