我在我的功能一個我設置其值爲聲明的全局命名計數器= 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