Global variable not set value in $.getJSON properly
<p>I have declared global variable named counter=0 on my index.html page inside head section </p>

<pre><code>&lt;script&gt;
var counter=0;
&lt;/script&gt;
</code></pre>

<p>now in my one of function i am setting its value as</p>

<pre><code>    function getCounter(param)
    {
        $.getJSON("somewebserviceURL&amp;format=json&amp;callback=?",
            function(data)
            {
                 $.each(data, function(i, item)
                    {
                        counter++;
                    });

            });
//I am not able to get the latest value here &amp; in upcoming functions which use this variable
         alert(counter);

    }
</code></pre>
