Skip to content

Commit 89ce0af

Browse files
togakangaroodmethvin
authored andcommitted
Ajax: $.post and $.get can now take an options object
Fixes jquerygh-1986 Closes jquerygh-1995
1 parent bb928bd commit 89ce0af

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/ajax.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,14 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
796796
data = undefined;
797797
}
798798

799-
return jQuery.ajax({
799+
// The url can be an options object (which then must have .url)
800+
return jQuery.ajax( jQuery.extend({
800801
url: url,
801802
type: method,
802803
dataType: type,
803804
data: data,
804805
success: callback
805-
});
806+
}, jQuery.isPlainObject( url ) && url ) );
806807
};
807808
});
808809

test/unit/ajax.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,26 @@ module( "ajax", {
20342034
});
20352035
});
20362036

2037+
asyncTest( "jQuery[get|post]( options ) - simple with xml", 2, function() {
2038+
jQuery.when.apply( jQuery,
2039+
jQuery.map( [ "get", "post" ] , function( method ) {
2040+
return jQuery[ method ]({
2041+
url: url( "data/name.php" ),
2042+
data: {
2043+
"xml": "5-2"
2044+
},
2045+
success: function( xml ) {
2046+
jQuery( "math", xml ).each(function() {
2047+
strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2048+
});
2049+
}
2050+
});
2051+
})
2052+
).always(function() {
2053+
start();
2054+
});
2055+
});
2056+
20372057
//----------- jQuery.active
20382058

20392059
test( "jQuery.active", 1, function() {

0 commit comments

Comments
 (0)