내 범위 밖의 내 인 그램 데이터에 액세스하면됩니다. 그래서 더 나은 당신이 함수를 호출 할 수 있습니다,자바 스크립트의 범위를 벗어난 Instagram 데이터에 액세스
function suatrootCallback(suatroot){
// code to handle suatroot/data.data
}
$(document).ready(function(){
var apiurl = "https://api.instagram.com/v1/users/4322593457/media/recent/?access_token=4322593457.15d3a7f.13779606843446ab834b0e8512412d4a&count=5&callback=?";
$.getJSON(apiurl, function (data) {
var suatroot = data.data; // do not create global variable
suatrootCallback(suatroot); // call the callback
$.each(suatroot, function (key, val) {
var itemobj = val.images.low_resolution.url;
var hrefobj = val.link;
var captobj = val.caption.text;
data = captobj; //Can I access this???????
var suatpaket = "<a target='_blank' href='"+hrefobj+"'><img src='" + itemobj + "'/><br>"+captobj+"<br></a>";
$(".instagram").append(suatpaket);
});
});
});
넣어 Console.log (suatroot); $ (document) .ready()의 끝에서 – Kenny
자바 스크립트는 아약스 요청의 응답을 따르지 않습니다. 한 줄씩 실행합니다. 그래서 $ .getJson 자바 스크립트가 나올 때까지 기다리지 않고 Consolo.Log 코드와 suatroot 변수에 전달합니다. 변수는 여기에 정의되어 있지 않습니다. – Mehmet