mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Ajax: Support null
as success functions in jQuery.get
According to the docs, one can use `null` as a success function in `jQuery.get` of `jQuery.post` so the following: ```js await jQuery.get( "https://httpbin.org/json", null, "text" ) ``` should get the text result. However, this shortcut hasn't been working so far. Fixes gh-4989 Closes gh-5139
This commit is contained in:
parent
8c7da22cae
commit
74978b7e89
@ -846,8 +846,9 @@ jQuery.extend( {
|
|||||||
jQuery.each( [ "get", "post" ], function( _i, method ) {
|
jQuery.each( [ "get", "post" ], function( _i, method ) {
|
||||||
jQuery[ method ] = function( url, data, callback, type ) {
|
jQuery[ method ] = function( url, data, callback, type ) {
|
||||||
|
|
||||||
// Shift arguments if data argument was omitted
|
// Shift arguments if data argument was omitted.
|
||||||
if ( typeof data === "function" ) {
|
// Handle the null callback placeholder.
|
||||||
|
if ( typeof data === "function" || data === null ) {
|
||||||
type = type || callback;
|
type = type || callback;
|
||||||
callback = data;
|
callback = data;
|
||||||
data = undefined;
|
data = undefined;
|
||||||
|
@ -15,7 +15,6 @@ var xhrSuccessStatus = {
|
|||||||
jQuery.ajaxTransport( function( options ) {
|
jQuery.ajaxTransport( function( options ) {
|
||||||
var callback;
|
var callback;
|
||||||
|
|
||||||
// Cross domain only allowed if supported through XMLHttpRequest
|
|
||||||
return {
|
return {
|
||||||
send: function( headers, complete ) {
|
send: function( headers, complete ) {
|
||||||
var i,
|
var i,
|
||||||
|
@ -2593,6 +2593,26 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
|
|||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
QUnit.test( "jQuery.get( String, null-ish, String ) - dataType with null callback (gh-4989)",
|
||||||
|
function( assert ) {
|
||||||
|
assert.expect( 2 );
|
||||||
|
var done = assert.async( 2 );
|
||||||
|
|
||||||
|
jQuery.get( url( "mock.php?action=json&header" ), null, "json" )
|
||||||
|
.then( function( json ) {
|
||||||
|
assert.deepEqual( json, { data: { lang: "en", length: 25 } },
|
||||||
|
"`dataType: \"json\"` applied with a `null` callback" );
|
||||||
|
done();
|
||||||
|
} );
|
||||||
|
|
||||||
|
jQuery.get( url( "mock.php?action=json&header" ), null, "text" )
|
||||||
|
.then( function( text ) {
|
||||||
|
assert.strictEqual( text, "{\"data\":{\"lang\":\"en\",\"length\":25}}",
|
||||||
|
"`dataType: \"text\"` applied with a `null` callback" );
|
||||||
|
done();
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
//----------- jQuery.getJSON()
|
//----------- jQuery.getJSON()
|
||||||
|
|
||||||
QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {
|
QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user