我在我的功能一个我设置其值为声明的全局命名计数器= 0变量我的index.html页头部分内全局变量未设置值正常
<script>
var counter=0;
</script>
现在
function getCounter(param)
{
$.getJSON("somewebserviceURL&format=json&callback=?",
function(data)
{
$.each(data, function(i, item)
{
counter++;
});
});
//I am not able to get the latest value here & in upcoming functions which use this variable
alert(counter);
}
可能重复://计算器.com/questions/3537434/cant-get-correct-return-value-from-an-jquery-ajax-call) – 2012-02-28 11:58:57