我正在编写一个小型 Flickr 图像采集器应用程序,我们在自己的服务器上有一个 JSON 代理。下面的函数从给定的照片集中抓取图像id。
function getPhotosFromPhotoset(p_id) {
    var data;
    $.getJSON('/flickr_get_photos', {
        photoset_id: p_id
    }, function(res) {
        data = res;
        console.log("res: " + JSON.stringify(data));
        if (res.status == 'ok') {
            if (res.data.length > 0) {
                //nada                                                                                                                            
            } else {
                data.status = "error: Photoset has no photos.";
            }
        } else {
            data.status = "An unknown error occurred; please try again.";
        }
    });
    return data; //undefined?!
}
为什么data突然变得未定义?当我console.log在里面时getJSON,它是完全有效的。