WETness getting you down? Fear not, the $.get and $.post methods are now 866% DRYer...
authorBen Alman <cowboy@rj3.net>
Sun, 26 Dec 2010 18:51:29 +0000 (18:51 +0000)
committerBen Alman <cowboy@rj3.net>
Sun, 26 Dec 2010 18:52:27 +0000 (18:52 +0000)
src/ajax.js

index 3f4f732..bac0ab1 100644 (file)
@@ -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.toLowerCase() ] = 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 );
        },