I guess this question isn't only specific to YUI, but that's the JS library I'm using and a specific answer would be helpful.
Basically when loading a page, I want a script to run a few XHRs using Y.io, and if they all return the data successfully then I want the script to move on to the next step, which will manipulate the data received.
I can think of a few ways of doing this, but they all seem a bit clumsy to me and I hope someone has a better suggestion. My ideas so far:
- Consolidate all the data I want into one JSON response, so if that one request is good, move on. (This is the solution I like least).
- When the first Y.io request returns successful, call the next, and so on, and when the last is successful then I know everything succeeded and move on to the next step of the script.
Any better ideas out there? I'm not really liking either of mine at the moment, but I'm leaning towards option two.