$(function () { //----------------------------------------------------------------------- // 2) Send a http request with AJAX <a href="http://api.jquery.com/jQuery.ajax/" target="_blank">http://api.jquery.com/jQuery.ajax/</a> //----------------------------------------------------------------------- $.ajax({ url: 'api.php', //the script to call to get data data: "", //you can insert url argumnets here to pass to api.php //for example "id=5&parent=6" dataType: 'json', //data format success: function(data) //on recieve of reply { var id = data[4]; //get id var vname = data[2]; //get name //-------------------------------------------------------------------- // 3) Update html content //-------------------------------------------------------------------- $('#output').html("<b>id: </b>"+id+"<b> name: </b>"+vname"<b> url: </b>"+url); //Set output element html //recommend reading up on jquery selectors they are awesome // <a href="http://api.jquery.com/category/selectors/" target="_blank">http://api.jquery.com/category/selectors/</a> } }); });
skrypt działa, ja próbuje go zmienić na coś takiego:
$(function () { $.ajax({ url: 'api.php', //the script to call to get data data: "", //you can insert url argumnets here to pass to api.php //for example "id=5&parent=6" dataType: 'json', //data format success: function(data) //on recieve of reply { var access_token = "..."; var id = data[4]; //get id var url = "https://api.instagram.com/v1/users/"+id+"?access_token="+access_token+"&callback=?"; $.getJSON(url, function(data) { $(".thumb").append("<img src='"+data.data.profile_picture+"' /><br/>");}); } }); });
Wiem, nawet w czym tkwi problem, mianowicie, plik api działa tak jak powinien, wyświetla dane z tabeli w formacie JSON, ale główny skrypt nic nie wyświetla. Odpowiedzialna za wyświetlanie jest ta część
$.getJSON(url, function(data) { $(".thumb").append("<img src='"+data.data.profile_picture+"' /><br/>");});
Ktoś mógłby mi pomóc to rozgryźć?