Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery.get:jQuery.post: Document issues with data: null with 3 params #1208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgol
Copy link
Member

@mgol mgol commented 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

@@ -15,7 +15,7 @@
<argument name="data" type="PlainObject" />
<argument name="textStatus" type="String"/>
<argument name="jqXHR" type="jqXHR"/>
<desc>A callback function that is executed if the request succeeds. Required if <code>dataType</code> is provided, but you can use <code>null</code> or <a href="/jQuery.noop/"><code>jQuery.noop</code></a> as a placeholder.</desc>
<desc>A callback function that is executed if the request succeeds. Required if <code>dataType</code> is provided, but you can use <code>null</code> or <a href="/jQuery.noop/"><code>jQuery.noop</code></a> as a placeholder. <strong>NOTE:</strong> In jQuery 3.x and older, when providing a <code>null</code> value for <code>success</code> you also have to provide the <code>data</code> parameter; you can set it to <code>undefined</code>.</desc>
Copy link
Member

Choose a reason for hiding this comment

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

Can set it to undefined or null right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically - probably yes - but I'd rather not advertise that. For example, in the success case, you can set it to null but not to undefined to trigger the documented behavior, which makes us treat the undefined value more as "parameter not passed" and null having some extra meanings in some cases.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

idk, it seems inconsistent to recommend null in one place and undefined in another. I'd probably use null, null, dataType myself.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to document null for the second parameter as well, we'd have to have some tests in jQuery for this. Currently, I believe we have none.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added these tests in jquery/jquery#5640. When merged & backported to 3.x-stable, I'll update this PR as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mgol mgol force-pushed the jquery-get-data-null branch 3 times, most recently from 4ee332d to 03bdec9 Compare November 18, 2022 12:32
@mgol mgol force-pushed the jquery-get-data-null branch from 03bdec9 to 66abf44 Compare October 27, 2023 13:28
@mgol mgol force-pushed the jquery-get-data-null branch from 66abf44 to d8fa4f5 Compare November 6, 2023 15:41
@mgol mgol force-pushed the jquery-get-data-null branch from d8fa4f5 to 5e558e0 Compare October 14, 2024 16:25
mgol added a commit to mgol/jquery that referenced this pull request Mar 17, 2025
Also, fix `mock.php` formatting to not fail the
`jQuery.get( String, null, String )` test in PHP mode.

Ref jquerygh-4989
Ref jquery/api.jquery.com#1208
@mgol mgol force-pushed the jquery-get-data-null branch from 5e558e0 to 05cab6f Compare March 24, 2025 16:56
mgol added a commit to jquery/jquery that referenced this pull request Mar 31, 2025
Also, fix `mock.php` formatting to not fail the
`jQuery.get( String, null, String )` test in PHP mode.

Closes gh-5640
Ref gh-4989
Ref jquery/api.jquery.com#1208
mgol added a commit to mgol/jquery that referenced this pull request Mar 31, 2025
Also, fix `mock.php` formatting to not fail the
`jQuery.get( String, null, String )` test in PHP mode.

Ref jquerygh-5640
Ref jquerygh-4989
Ref jquery/api.jquery.com#1208
mgol added a commit to mgol/jquery that referenced this pull request Apr 1, 2025
Also, fix `mock.php` formatting to not fail the
`jQuery.get( String, null, String )` test in PHP mode.

Ref jquerygh-5640
Ref jquerygh-4989
Ref 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
@mgol mgol force-pushed the jquery-get-data-null branch from 05cab6f to 3c1c919 Compare April 1, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants