title: How to check if javascript function is ready/done (jQuery)
body: <p>I am working on a learning planner which gets its data (languagekeys, tasks, activities, etc.) from a database. Because I need a JSON string, I encode it with <code>json_encode</code> to work with it in JavaScript.
  I have a different function (for keys, tasks, activities, etc.) which gets this data and writes it into an array.</p>
  
  <pre><code>function get_tasks(start_date,end_date){
  
      maxsubtasks=0;
      maxtasks=0;
  
      $.getJSON(json_data+"?t_startdate="+start_date+"&amp;t_enddate="+end_date, function(data) {  
  
          tasks=new Array();
  
          $.each(data.tasks, function(i,item){
  
              tasks[i]= new Object();
              tasks[i]["t_id"]=item.t_id;
              tasks[i]["t_title"]=item.t_title;
              tasks[i]["t_content"]=item.t_content;
              . . .
  
              if ( i &gt; data.tasks.length) return false;    
              maxtasks = data.tasks.length;
              if(item.t_parent &gt; 0){
                  maxsubtasks++;
              }
          });         
      });
      return true;
  }
  </code></pre>
  
  <p>Everything is working just fine. I need some help, because I now have to call this function in <code>$(document).ready()</code>. I want to build my learning planner only once the function <code>get_tasks()</code> is complete (the array is filled with data).  Otherwise, I will get errors.</p>
  
  <p>How can this be solved?</p>
  
  <p>Here is what I have in <code>$(document).ready()</code>:</p>
  
  <pre><code>if(get_tasks(first_day,last_day) &amp;&amp; get_tmp_data()){ // If this function is done
      // This function should be fired -- just like a callback in jQuery
      init_learnplanner();
  }
  </code></pre>