diff options
author | George Mauer <gmauer@gmail.com> | 2015-01-05 21:00:12 -0600 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2015-01-11 20:32:38 -0500 |
commit | 89ce0af2cf7f001647e74fc1de92ce94a51fd5c2 (patch) | |
tree | 251c899a3fe79bea5d0288c5f151eeffdd4eea26 | |
parent | bb928bde7e7b85357fef3fedd450b04c03e965d7 (diff) | |
download | jquery-89ce0af2cf7f001647e74fc1de92ce94a51fd5c2.tar.gz jquery-89ce0af2cf7f001647e74fc1de92ce94a51fd5c2.zip |
Ajax: $.post and $.get can now take an options object
Fixes gh-1986
Closes gh-1995
-rw-r--r-- | src/ajax.js | 5 | ||||
-rw-r--r-- | test/unit/ajax.js | 20 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/ajax.js b/src/ajax.js index dafbc6082..a9faee78d 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -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 ) ); }; }); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index b41654db9..29a4dfb46 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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() { |