Javascript - Control flow
<p>I need a little help in best practices around "control flow" within javascript. In the below example my updateUI function is not properly working because my saveData function has not yet completed.</p>

<pre><code>function save(data){
   saveData(data);
   updateUI();
}
</code></pre>

<p>For a temporary fix, I did this</p>

<pre><code>function save(data){
if(saveData(data)){
   updateUI();
   }
}
</code></pre>

<p>Update: Here is my saveData method</p>

<pre><code>function saveData(data){

$.ajax({
    url: url, // a variable, not important for this example
    data: data,
    type: "post",
    dataType: "json",
    success: function(data) { return true; },
    error: function(e) {
        console.log(e);
    }
})
</code></pre>

<p>I feel like I should learn the "standard" way, if such one exists.</p>
