function getData() {
var photo,
comment,
url;
$.getJSON('http://url.info/verify/settings.php', function (data) {
photo = data.photoMSG;
comment = data.commentMSG;
url = data.photoURL
});
console.log(photo); //undefined
console.log(comment); //undefined
console.log(url); //undefined
}
我得到的控制檯日誌中未定義的所有這些...如何讓這些3個變量在getJOSN塊之外可見?我知道這已被問到x100次,我嘗試了windiw.varName但仍然是同樣的事情。javascript可變範圍問題undefined
異步調用*異步*。在回調函數中添加一個'console.log('now received');''! – deceze