From: George Mauer Date: Tue, 6 Jan 2015 03:00:12 +0000 (-0600) Subject: Ajax: $.post and $.get can now take an options object X-Git-Tag: 3.0.0-alpha1+compat~145 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=26150f0910a0b0d933df92cd354c6735c3dc9078;p=jquery.git Ajax: $.post and $.get can now take an options object Fixes gh-1986 Closes gh-1995 (cherry picked from commit 89ce0af2cf7f001647e74fc1de92ce94a51fd5c2) --- diff --git a/src/ajax.js b/src/ajax.js index d8450e1c3..d2b40d338 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -798,13 +798,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 ) ); }; }); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 35db61699..89161a928 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2050,6 +2050,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() {