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.

@mgol mgol force-pushed the jquery-get-data-null branch 3 times, most recently from 4ee332d to 03bdec9 Compare November 18, 2022 12:32
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
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