8000 Ajax: Support `null` as success functions in `jQuery.get` by mgol · Pull Request #5139 · jquery/jquery · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

mgol
Copy link
Member
@mgol mgol commented Oct 11, 2022

Summary

According to the docs, one can use null as a success function in jQuery.get
of jQuery.post so the following:

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

Checklist

@mgol mgol added Ajax Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Oct 11, 2022
@mgol mgol added this to the 4.0.0 milestone Oct 11, 2022
@mgol mgol self-assigned this Oct 11, 2022
@mgol
Copy link
Member Author
mgol commented Oct 11, 2022

I added this to the discussion list to discuss whether we want this in 3.x or not. This has a chance of breaking some code; on the other hand, documentation states the behavior from this PR.

@mgol mgol marked this pull request as draft October 11, 2022 14:41
@mgol mgol removed Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. Needs review labels Oct 11, 2022
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
@mgol mgol force-pushed the get-null-success-fn branch from d75d41e to aa17bef Compare October 15, 2022 08:33
@mgol mgol changed the title Ajax: Support null & undefined as success functions in jQuery.get Ajax: Support null as success functions in jQuery.get Oct 15, 2022
@mgol mgol added Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Oct 15, 2022
@mgol mgol marked this pull request as ready for review October 15, 2022 08:33
if ( typeof data === "function" ) {
// Shift arguments if data argument was omitted.
// Handle the null callback placeholder.
if ( typeof data === "function" || data === null ) {
Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member Author

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 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur.

@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Oct 17, 2022
@timmywil
Copy link
Member

Since this has been like this for so long, we're going to leave 3.x unchanged and fix this for 4.0.

@mgol mgol removed the Needs review label Oct 17, 2022
mgol added a commit to mgol/api.jquery.com that referenced this pull request Oct 17, 2022
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
@mgol
Copy link
Member Author
mgol commented Oct 17, 2022

I submitted the API PR at jquery/api.jquery.com#1208.

@mgol mgol merged commit 74978b7 into jquery:main Oct 17, 2022
@mgol mgol deleted the get-null-success-fn branch October 17, 2022 16:54
mgol added a commit to mgol/api.jquery.com that referenced this pull request Nov 18, 2022
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Nov 18, 2022
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Nov 18, 2022
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Oct 27, 2023
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Nov 6, 2023
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Oct 14, 2024
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Mar 24, 2025
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Apr 1, 2025
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request Apr 14, 2025
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request May 5, 2025
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
mgol added a commit to mgol/api.jquery.com that referenced this pull request May 12, 2025
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
mgol added a commit to jquery/api.jquery.com that referenced this pull request May 12, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Null value in jQuery.get doesn't allow use of dataType
3 participants
0