Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
$.Ajax call for multiple groups from separate sources, if a single source fails, typeahead remains in fetching data view #401
$.Ajax call for multiple groups from separate sources, if a single source fails, typeahead remains in fetching data view
So I have a need to fetch data for 3 groups, 2 of those are a local call so combined into a single request.
If the external source fails. (returns a 404) then the spinning loading view continues. If I comment out
Then it works as expected displaying the local data and gracefully ignoring the failed external call.
I have noticed with some console logging that even though it might be the same call to a non existant external endpoint (to mimic failure) sometimes (typeof jqXHR !== "object") is false other times true.. so seems inconsistent.
I wonder if the distinction here could be between an aborted request rather than a failed request?
I suppose I could workaround this with combining the sources externally, but thought I'd report anyway.
PS: great job ;-)
pushed a commit
May 14, 2018
Hey @mistyn8 gj for debugging it out, you figured out the right line! Althrough this is needed but only for aborted request let me explain. If the first request is sent and a subsequent request is set before the first one(s) finishes typeahead will think that the first request is still valid and populate the data from it. Instead what we want to do is return an do nothing for aborted requests and only consider the latest requests as the source of truth. I've modified the condition to also include "error" type of requests (don't know why I haven't caught this before...) so Typeahead is populated correctly if 1 or multiple requests fails but at least 1 succeeds.