8000 jQuery.get() 4.0 backward compatibility issue · Issue #5426 · jquery/jquery · GitHub
[go: up one dir, main page]

Skip to content

jQuery.get() 4.0 backward compatibility issue #5426

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

Closed
hugodevreugd opened this issue Mar 1, 2024 · 8 comments
Closed

jQuery.get() 4.0 backward compatibility issue #5426

hugodevreugd opened this issue Mar 1, 2024 · 8 comments
Labels

Comments

@hugodevreugd
Copy link

The jQuery api describes jQuery.get as: jQuery.get( url [, data ] [, success ] [, dataType ] )].

In jQuery 3.5.7 this code, with null for the data parameter, works:

var jqxhr = $.get( "example.php", null, function() {
  alert( "success" );
});

In jQuery 4.0 this code doesn't work anymore, you have to remove the null parameter:

var jqxhr = $.get( "example.php", function() {
  alert( "success" );
});

A small change, but this breaks backward compatibility.

@dmethvin
Copy link
Member
dmethvin commented Mar 2, 2024

The docs don't say that you can use null for data, it's supposed to be an object or string. According to #5139 (comment) and the docs, null is used to omit the callback. The second example omits data without needing to mention it at all. Worth a mention in the upgrade guide though I guess?

@timmywil timmywil added the Docs label Mar 3, 2024
@timmywil
Copy link
Member
timmywil commented Mar 3, 2024

Thanks for the issue and thanks for pointing that out, Dave. We'll mention it in the upgrade guide.

@rexfactor

This comment was marked as off-topic.

@Chefaroon
Copy link

The docs don't say that you can use null for data, it's supposed to be an object or string.

Ehm, in JavaScript "null" IS an Object. I don't agree with it, but it is. Easiest check - development console:

> console.log(typeof null);
object

@mgol
Copy link
Member
mgol commented Oct 17, 2024

null is not an object. The fact typeof null === "object" is a language bug but it doesn't change the fact that null is a primitive, not an object.

See:

Also, note the error message here:

Object.getPrototypeOf(null);
// Uncaught TypeError: Cannot convert undefined or null to object

@rexfactor

This comment has been minimized.

@rexfactor

This comment has been minimized.

@mgol
Copy link
Member
mgol commented May 12, 2025

Issues have been documented at jquery/api.jquery.com#1208 and we added tests in a few Core PRs. I think that's all we need here.

@mgol mgol closed this as completed May 12, 2025
Sign up for free 477A to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

6 participants
0