Skip to content

Commit

Permalink
Ajax: $.post and $.get can now take an options object
Browse files Browse the repository at this point in the history
Fixes gh-1986
Closes gh-1995
(cherry picked from commit 89ce0af)
  • Loading branch information
togakangaroo authored and dmethvin committed Jan 12, 2015
1 parent 0771973 commit 26150f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ajax.js
Expand Up @@ -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 ) );
};
});

Expand Down
20 changes: 20 additions & 0 deletions test/unit/ajax.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 26150f0

Please sign in to comment.