$(document).ready with jQuery
<p>I code with jquery. My problem is with:</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(document).ready(function() {
function1();
function2();
});
&lt;/script&gt;
</code></pre>

<p>Sometimes no function works and sometimes the functions work but they are not working in order!!
function1:</p>

<pre><code>function getnameCategories1()
{

    var request = new XMLHttpRequest();
    if(i&lt;idCategories.length)
        {
            request.open("GET","http://patisserie-orient.fr/prestashop/prestashop/api/categories/"+idCategories[i]+"?PHP_AUTH_USER="+PHP_AUTH_USER+"&amp;ws_key="+ws_key,true);

            request.onreadystatechange = function()
                {
                    if(request.readyState==4)
                    {
                        //alert("Status2 is  "+request.status);
                        if (request.status == 200 || request.status == 0)
                        {
                            response1  = request.responseXML.documentElement;
                            nameCategories[i] = response1.getElementsByTagName('language')[0].firstChild.data;
                            //alert(nameCategories[i]);
                            $('#im'+i).html(nameCategories[i]);
                            $('#a'+i).show();
                            i++;


                         }
                     }
                }

            request.send();

        }   
    else
        {
            return;
        }

}
</code></pre>

<p>function2:</p>

<pre><code>function getCategories()
{

    var request = new XMLHttpRequest();

    request.open("GET","http://patisserie-orient.fr/prestashop/prestashop/api/categories?PHP_AUTH_USER="+PHP_AUTH_USER+"&amp;ws_key="+ws_key,true);
    request.onreadystatechange = function()
    {
        if(request.readyState==4)
        {
            //alert("Status is:  "+request.status);
            if (request.status == 200 || request.status == 0)
            {
                response  = request.responseXML.documentElement;
                i=0;
                while(response.getElementsByTagName('category')[i]!=undefined)
                    {
                        idCategories[i]=response.getElementsByTagName('category')[i].getAttribute('id') ;
                        //alert(idCategories[i]);
                        i=i+1;
                    }

             }
         }

    }
    request.send();
}
</code></pre>

<p>Sometimes even just an alert in $(document).ready does not work</p>
