Skip to content

Commit 26150f0

Browse files
togakangaroodmethvin
authored andcommitted
Ajax: $.post and $.get can now take an options object
Fixes jquerygh-1986 Closes jquerygh-1995 (cherry picked from commit 89ce0af)
1 parent 0771973 commit 26150f0

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
@@ -798,13 +798,14 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
798798
data = undefined;
799799
}
800800

801-
return jQuery.ajax({
801+
// The url can be an options object (which then must have .url)
802+
return jQuery.ajax( jQuery.extend({
802803
url: url,
803804
type: method,
804805
dataType: type,
805806
data: data,
806807
success: callback
807-
});
808+
}, jQuery.isPlainObject( url ) && url ) );
808809
};
809810
});
810811

test/unit/ajax.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,26 @@ module( "ajax", {
20502050
});
20512051
});
20522052

2053+
asyncTest( "jQuery[get|post]( options ) - simple with xml", 2, function() {
2054+
jQuery.when.apply( jQuery,
2055+
jQuery.map( [ "get", "post" ] , function( method ) {
2056+
return jQuery[ method ]({
2057+
url: url( "data/name.php" ),
2058+
data: {
2059+
"xml": "5-2"
2060+
},
2061+
success: function( xml ) {
2062+
jQuery( "math", xml ).each(function() {
2063+
strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2064+
});
2065+
}
2066+
});
2067+
})
2068+
).always(function() {
2069+
start();
2070+
});
2071+
});
2072+
20532073
//----------- jQuery.active
20542074

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

0 commit comments

Comments
 (0)