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 3.x ajax does not work async = false #3740

Closed
mariuszkrzaczkowski opened this issue Jul 31, 2017 · 6 comments
Closed

jquery 3.x ajax does not work async = false #3740

mariuszkrzaczkowski opened this issue Jul 31, 2017 · 6 comments

Comments

@mariuszkrzaczkowski
Copy link

Description

I updated jQuery from 2.2.4 to 3.2.1 and it stopped working properly with ajax parameter async = false.
How can I solve this problem?

@mgol
Copy link
Member

mgol commented Jul 31, 2017

Did you read the issue template? It asked for a test case. With such a short report there's nothing we can do.

@mariuszkrzaczkowski
Copy link
Author

mariuszkrzaczkowski commented Jul 31, 2017

2.2.4: https://jsfiddle.net/5jmprj0x/
3.2.1: https://jsfiddle.net/4ngd9g4n/1/

The result should be that
1111
2222
33333

@mgol
Copy link
Member

mgol commented Jul 31, 2017

This is not the AJAX call that's asynchronous in your example but the invocation of the handler attached via .then(); they're always asynchronous now.

See https://jquery.com/upgrade-guide/3.0/#callback-invocation for more information, in particular:

Another behavior change required for Promises/A+ compliance is that Deferred .then() callbacks are always called asynchronously. Previously, if a .then() callback was added to a Deferred that was already resolved or rejected, the callback would run immediately and synchronously.

@mgol mgol closed this as completed Jul 31, 2017
@mariuszkrzaczkowski
Copy link
Author

Would you help with the improvement of this code?

@mgol
Copy link
Member

mgol commented Jul 31, 2017

Synchronous AJAX is generally a bad idea but a quick fix would be to switch from .then to .done.

@mariuszkrzaczkowski
Copy link
Author

Thanks, it works

@lock lock bot locked as resolved and limited conversation to collaborators Jun 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants