how to stop first function get json till second function getjson return data
<p>Hi Guys I have a problem to make a accordion menu (Nested) in Apache Cordova.
I have to function with two getjson to get categories and sub categories.
Middle of first function i call second function to get sub Categories,But Second Function Did not return my favorite string that is contains htmlSubCategories and it returns undefined value</p>

<pre><code>     //Function 1
  var Categoriesdata = [];
function getCategories()
{
    var htmlCategories = "";
    $.getJSON('http://example.com/Categories', null, function (Categoriesdata) {
        for (var i = 0; i &lt; Categoriesdata.length ; i++)
        {
            {
                htmlCategories += "&lt;li&gt;";
                htmlCategories += "&lt;a href='#'&gt; " + Categoriesdata[i].Text + "&lt;/a&gt;";
                htmlCategories += getCategoriesRev(Categoriesdata[i].Id);
                htmlCategories += "&lt;/li&gt;";
            }
       }
            $(".Categories").html(htmlCategories);  
    });
}

  //Function 2
function getCategoriesRev(Id)
{
    var htmlSubCategories = "";
    $.getJSON('http://example.com/CategoriesRev', { id: Id }, function (CategoriesdataRev) {

        if (CategoriesdataRev.length &gt; 0)
        { 
            for (var j = 0; j &lt; CategoriesdataRev.length; j++) {
                htmlSubCategories += "&lt;li&gt;";
                htmlSubCategories += "&lt;a href='#'&gt; " + CategoriesdataRev[j].Text + "&lt;/a&gt;";
                htmlSubCategories += getCategoriesRev(CategoriesdataRev[j].Id);
                htmlSubCategories += "&lt;/li&gt;";
            }
            htmlSubCategories = "&lt;ul class='submenu'&gt;" + htmlSubCategories + "&lt;/ul&gt;";

        }
  return htmlSubCategories;
    });

}
</code></pre>