global variable in javascript used in a ajax call
<p>I declared a global variable <code>var idCategories= new Array();</code> in my <code>file.js</code>
I use it in this function</p>

<pre><code>function test() {
    $.ajax({
        type: "GET",
        url: "http://my_site/api/categories?ws_key=" 
             + ws_key  
             + "&amp;PHP_AUTH_USER=" + PHP_AUTH_USER,
        dataType: "xml",
        success: parseXml
    });
    function parseXml(xml) {
        var i = 0;
        $(xml).find("category").each(function () {
            idCategories[i] = $(this).attr('id');
            // length increments at each iteration
            alert("length=" + idCategories.length);                 
            i = i + 1;
        });
    }
    alert("length=" + idCategories.length); //returns 0
}
</code></pre>

<p>in the function <code>parseXml(xml)</code> the array length is well incremented but outside of this function length = 0! so that I can't use the array <code>idCategories</code> in another function!</p>
