<分区>
Possible Duplicate:
JavaScript asynchronous return value / assignment with jQuery
我有以下 javascript 代码,time.php 文件使用 json_encode 函数输出分钟和小时。如果我将 console.log 移到 getJSON 函数内,它会找到正确的值,但是当我将它移到函数外时,它会显示为未定义。
var my_hour;
$.getJSON('../scripts/time.php', function(data) {
my_hour = data.hour;
});
console.log(my_hour);