Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I see a lot of questions (e.g. here or here, just in the past couple of hours) where the poster is making an Ajax call within a function (and doing something with the results in a callback) and doesn't understand why the results aren't available either later in the parent function or as the return value of the parent function. I.e. they don't understand that Ajax is asynchronous.

Unfortunately since they don't understand the problem, the questions are often phrased in very different ways -- they think they have an issue with variable definition, or return values, or scope. This makes it hard to close such questions as duplicates.

So, two questions: 1) if we were to close such questions as duplicates, is there a "canonical" answer that would be good to use, and 2) how do we deal with the fact that these are, in fact, duplicates (in terms of the deeper issue), but aren't phrased as such -- really aren't "exact duplicates" -- because of misunderstanding?

share|improve this question

closed as off-topic by Laura Jul 31 '14 at 15:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question pertains only to a specific site in the Stack Exchange Network. Questions on Meta Stack Exchange should pertain to our network or software that drives it as a whole, within the guidelines defined in the help center. You should ask this question on the meta site where your concern originated." – Laura
If this question can be reworded to fit the rules in the help center, please edit the question.

1) yeah, probably. You should look for a good general version, such as "why is my return value null?" which highlights the asynchronous nature. 2) close them as dupes. – Won't Dec 7 '11 at 18:45
3) Answer them and then close them as Too Localized – user7116 Dec 7 '11 at 19:17
For these, I usually count on SLaKs to come around after a few minutes and welcome the OP to the world of async. – Andrew Whitaker Jan 6 '12 at 19:37
Perhaps this question should be migrated back to mSO – Travis J Jul 29 '14 at 23:54

lyI don't think there can be a canonical answer to mark everything a duplicate of as every question is asked in a different context, in a different way and likely has different symptoms and different issues. The OP would likely not feel like they got their situation explained appropriately if their question was just marked a duplicate of some other answer that attempts to explain asynchronous in general.

As I've answered a number of these questions myself with separately written answers each time. What I think is needed is a very good reference to point to that describes all the issues with asynchronous and offers both good code examples and common mistake code examples. That reference can then be cited along with a small amount of explanation related to the specific question.

I certainly do agree with you that this is a common issue as here are a few "asynchronous" answers I've provided:

share|improve this answer

There is actually a canonical answer to this highly popular type of question for javascript. It is also the first result in the frequent tab for javascript on Stack Overflow (not that anyone looks there who is asking about these it seems).

The canonical answer is here: How to return the response from an Ajax call? by Felix Kling (243k rep)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged .