diff --git a/src/ajax.js b/src/ajax.js index dc9fb242b..36a9c9b57 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -846,8 +846,9 @@ jQuery.extend( { jQuery.each( [ "get", "post" ], function( _i, method ) { jQuery[ method ] = function( url, data, callback, type ) { - // Shift arguments if data argument was omitted - if ( typeof data === "function" ) { + // Shift arguments if data argument was omitted. + // Handle the null callback placeholder. + if ( typeof data === "function" || data === null ) { type = type || callback; callback = data; data = undefined; diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index a024bb236..528a5c748 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -15,7 +15,6 @@ var xhrSuccessStatus = { jQuery.ajaxTransport( function( options ) { var callback; - // Cross domain only allowed if supported through XMLHttpRequest return { send: function( headers, complete ) { var i, diff --git a/test/data/mock.php b/test/data/mock.php index c72bea9f3..0cb88cf47 100644 --- a/test/data/mock.php +++ b/test/data/mock.php @@ -95,9 +95,9 @@ QUnit.assert.ok( true, "mock executed");'; } if ( isset( $req->query['array'] ) ) { - echo '[ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ]'; + echo '[{"name":"John","age":21},{"name":"Peter","age":25}]'; } else { - echo '{ "data": {"lang": "en", "length": 25} }'; + echo '{"data":{"lang":"en","length":25}}'; } } @@ -112,8 +112,8 @@ QUnit.assert.ok( true, "mock executed");'; $callback = $_POST['callback']; } $json = isset( $req->query['array'] ) ? - '[ { "name": "John", "age": 21 }, { "name": "Peter", "age": 25 } ]' : - '{ "data": { "lang": "en", "length": 25 } }'; + '[{"name":"John","age":21},{"name":"Peter","age":25}]' : + '{"data":{"lang":"en","length":25}}'; echo cleanCallback( $callback ) . '(' . $json . ')'; } diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 05dd7d36c..18e36489d 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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() QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {