Organizing Javascript with callbacks
<p>I am trying to figure out the best way to organize a bunch of AJAX methods on my site. The problem is that I want to run a bunch of callbacks after each one is received. Here's an example (assume each method runs asynchronously):</p>

<pre><code>Log_in_user
    if response received and call was successful
        get_user's_data
            if response received and call was successful
                alert user
</code></pre>

<p>Hopefully by now the problem is clear. Because each method runs asynchronously, the code will not run in order. If instead, I want to pass the next function to run as a callback to run after the function that proceeds it, I will have to pass an increasingly large number of callbacks to the first function depending on how many things I want to happen after each asynchronous method returns. For example, in this case, I will have to pass two callbacks to the Log_in_user function Log_in_user(get_user's_data,alert_user). The more callbacks I have running after each other, the more callbacks I will have to pass to the original Log_in_user function.</p>

<p>Is there a more modular and better organized way to do this?</p>
