From: Colin Snover Date: Mon, 27 Dec 2010 02:56:20 +0000 (-0600) Subject: DRY out $.get and $.post. Fixes #7847. Thanks to cowboy for the patch. X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=4443371dbaf751ce0d0d92e40f924e41fbd7b54c;hp=52b1709b94cf631e0641eebfa4f76b101528d93b DRY out $.get and $.post. Fixes #7847. Thanks to cowboy for the patch. --- diff --git a/src/ajax.js b/src/ajax.js index 3f4f732..18ea203 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -113,9 +113,8 @@ jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".sp }; }); -jQuery.extend({ - - get: function( url, data, callback, type ) { +jQuery.each( [ "get", "post" ], function( i, method ) { + jQuery[ method ] = function( url, data, callback, type ) { // shift arguments if data argument was omited if ( jQuery.isFunction( data ) ) { type = type || callback; @@ -124,13 +123,16 @@ jQuery.extend({ } return jQuery.ajax({ - type: "GET", + type: method, url: url, data: data, success: callback, dataType: type }); - }, + }; +}); + +jQuery.extend({ getScript: function( url, callback ) { return jQuery.get(url, null, callback, "script"); @@ -140,23 +142,6 @@ jQuery.extend({ 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 ) { jQuery.extend( jQuery.ajaxSettings, settings ); },