]> source.dussan.org Git - jquery.git/commitdiff
Ajax: $.post and $.get can now take an options object
authorGeorge Mauer <gmauer@gmail.com>
Tue, 6 Jan 2015 03:00:12 +0000 (21:00 -0600)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 12 Jan 2015 01:32:38 +0000 (20:32 -0500)
Fixes gh-1986
Closes gh-1995

src/ajax.js
test/unit/ajax.js

index dafbc6082b386469a1c474c093f8b07f6537615a..a9faee78d212489724450893c931e1915cea7051 100644 (file)
@@ -796,13 +796,14 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
                        data = undefined;
                }
 
-               return jQuery.ajax({
+               // The url can be an options object (which then must have .url)
+               return jQuery.ajax( jQuery.extend({
                        url: url,
                        type: method,
                        dataType: type,
                        data: data,
                        success: callback
-               });
+               }, jQuery.isPlainObject( url ) && url ) );
        };
 });
 
index b41654db91c160e4e87afc571cffd3ed9c5f9c57..29a4dfb46e35c73b37eebe71a2e2c80b37bee791 100644 (file)
@@ -2034,6 +2034,26 @@ module( "ajax", {
                });
        });
 
+       asyncTest( "jQuery[get|post]( options ) - simple with xml", 2, function() {
+               jQuery.when.apply( jQuery,
+                       jQuery.map( [ "get", "post" ] , function( method ) {
+                               return jQuery[ method ]({
+                                       url: url( "data/name.php" ),
+                                       data: {
+                                               "xml": "5-2"
+                                       },
+                                       success: function( xml ) {
+                                               jQuery( "math", xml ).each(function() {
+                                                       strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
+                                               });
+                                       }
+                               });
+                       })
+               ).always(function() {
+                       start();
+               });
+       });
+
 //----------- jQuery.active
 
        test( "jQuery.active", 1, function() {