Chevy787
Chevy787

Reputation: 45

Is it okay to use synchronous AJAX for this purpose?

Basically, I'm looping through a query of FOOD in my webpage.
Now each food in a different table, FLAVOR (linked by a unique FOOD ID), have a flavor.
Now, while I loop through the FOOD, is it okay to grab the flavor with a synchronous AJAX call or am I being stupid and should do something else?

The reason I ask is since from what I understand synchronous AJAX calls should be avoided as they aren't exactly the optimal way to do things. I just can't think of a good way to do it, as I can't do it as a callback function for the reason that it'd break out of the FOOD loop that goes through the FOOD query.

Upvotes: 0

Views: 70

Answers (1)

Brad
Brad

Reputation: 163313

Synchronous AJAX is never a good idea. Since you need to wait for many actions to finish, consider using jQuery's Deferred object.

http://api.jquery.com/category/deferred-object/

You can use an array of them as well: https://stackoverflow.com/a/5627301/362536

Upvotes: 1

Related Questions