Ajax: Support null as success functions in jQuery.get#5139
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.getnull 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.
@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.
| jQuery.ajaxTransport( function( options ) { | ||
| var callback; | ||
|
|
||
| // Cross domain only allowed if supported through XMLHttpRequest |
There was a problem hiding this comment.
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 ) { |
|
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
nullas a success function injQuery.getof
jQuery.postso the following:should get the text result. However, this shortcut hasn't been working so far.
Fixes gh-4989
Checklist
data: nullwith 3 params api.jquery.com#1208