-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Ajax: Support null
as success functions in jQuery.get
#5139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to o 8000 ur terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I added this to the discussion list to discuss whether we want this in |
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 jquerygh-4989
d75d41e
to
aa17bef
Compare
null
& undefined
as success functions in jQuery.get
null
as success functions in jQuery.get
if ( typeof data === "function" ) { | ||
// Shift arguments if data argument was omitted. | ||
// Handle the null callback placeholder. | ||
if ( typeof data === "function" || data === null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gibson042 allowing undefined
here would break the 4-param signature with the second parameter (data
) being undefined
which is e.g. used in the $.getScript
definition. We could add more checks to make it work but I thought in that case it may be better to just allow null
. null
is not an allowed data
value so we don’t have a conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur.
@@ -15,7 +15,6 @@ var xhrSuccessStatus = { | |||
jQuery.ajaxTransport( function( options ) { | |||
var callback; | |||
|
|||
// Cross domain only allowed if supported through XMLHttpRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated but this comment has long been invalid… We only have support checks on 3.x-stable
here.
if ( typeof data === "function" ) { | ||
// Shift arguments if data argument was omitted. | ||
// Handle the null callback placeholder. | ||
if ( typeof data === "function" || data === null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur.
Since this has been like this for so long, we're going to leave 3.x unchanged and fix this for 4.0. |
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
I submitted the API PR at jquery/api.jquery.com#1208. |
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Ref jquery/jquery#4989 Ref jquery/jquery#5139
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Closes jquerygh-1208 Ref jquery/jquery#4989 Ref jquery/jquery#5139 Ref jquery/jquery#5640 Ref jquery/jquery#5645 Ref jquery/jquery#5646
In jQuery 3.x and older, when providing a `null` value for `success` you also have to provide the `data` parameter; you can set it to `undefined`. Document this restriction of `jQuery.get` & `jQuery.post`. Closes gh-1208 Ref jquery/jquery#4989 Ref jquery/jquery#5139 Ref jquery/jquery#5640 Ref jquery/jquery#5645 Ref jquery/jquery#5646
Summary
According to the docs, one can use
null
as a success function injQuery.get
of
jQuery.post
so the following:should get the text result. However, this shortcut hasn't been working so far.
Fixes gh-4989
Checklist
data: null
with 3 params api.jquery.com#1208