-1

I am trying to build urls to thumbs of photsets, starting with the 'farm' value from the json feed. I cant see why this is not working..?

    <!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ajax_get_json(){
    var menu = document.getElementById("menu");
    var thumbURL = new XMLHttpRequest();
    thumbURL.open("GET", "http://api.flickr.com/services/rest/?&method=flickr.photosets.getList&api_key=797507e576c902b2ffb0c8494fb368ab&user_id=37003559@N03&format=json&jsoncallback=?", true);
    thumbURL.setRequestHeader("Content-type", "application/json", true);
    thumbURL.onreadystatechange = function() {
        if(thumbURL.readyState == 4 && thumbURL.status == 200) {
            var data = JSON.parse(thumbURL.responseText);
            menu.innerHTML = "";
            for(var obj in data){
                menu.innerHTML += data[obj].photosets.photoset.id+"<hr />";
            }
        }
    }
    thumbURL.send(null);
    menu.innerHTML = "requesting...";
}
</script>
</head>
<body>
<div id="menu"></div>
<script type="text/javascript">ajax_get_json();</script>

</body>
</html>

What did i miss..?

vincentieo
  • 940
  • 2
  • 13
  • 28

1 Answers1

1
function ajax_get_json(){
    var menu = document.getElementById("menu");
    var thumbURL = new XMLHttpRequest();
    thumbURL.open("GET", "https://api.flickr.com/services/rest/?&method=flickr.photosets.getList&api_key=797507e576c902b2ffb0c8494fb368ab&user_id=37003559@N03&format=json&jsoncallback=process", true);
    thumbURL.onreadystatechange = function() {
        if(thumbURL.readyState == 4 && thumbURL.status == 200) {
            eval(thumbURL.responseText);
        }
    }
    thumbURL.send(null);
    menu.innerHTML = "requesting...";
}

function process(data) {
    var menu = document.getElementById("menu");
    menu.innerHTML = "";
    var sets = data.photosets.photoset;
    var max = sets.length;

    for(var i = 0; i < max; i++) {
        menu.innerHTML += sets[i].id+"<hr />"
    }    
}

http://jsfiddle.net/2BTrQ/10/

salexch
  • 2,644
  • 1
  • 20
  • 17
  • Excellent, thanks, worked a charm...pulling thumbs and set titles into a nice gallery now. – vincentieo Jan 24 '13 at 19:53
  • Hi, thanks for the help, unfortunately i have just discovered that it is not compatible with IE. Here is a fiddle of where I am at so far... http://jsfiddle.net/vincentieo/wLtsG/5/ simply cant see what the problem is, there are no errors in js that i can see. any help / suggestions would be greatly appreciated. thanks, vince – vincentieo Feb 08 '13 at 14:47
  • why are these fiddles no longer working? Did flickr change the way they could be accessed? – ayjay Oct 11 '14 at 22:27
  • @ayjay maybe flicker changed their api – salexch Oct 13 '14 at 04:18