0

Using Flickr API, Javascript/JQuery, and AJAX, I have the follow code:

        function getRequest(arguments)
    {
        var requestinfo;
        $.ajax({
            type: 'GET',
            url: flickrurl + '&'+ arguments + '&jsoncallback=jsonCallback',
            async: false,
            jsonpCallback: 'jsonCallback',
            dataType: 'jsonp',
            success: function (json)
            {
                requestinfo = json;
                //Parse attempt requestinfo = $.parseJSON(json);
                //Old method return json;
            }
        });
        return requestinfo;
    }

When the response is received and I attempt to assign the json (the response) data to the variable, requestinfo, (or even if I do a straight 'return json' line) I get an error indicating the returned value is undefined. Upon fooling with the success function, I notice that any attempts to parse the response fails due to 'json' being read as [object Object] instead of the JSON response.

Is the response already in array format? If not, how can I get it to that point?

Here is an example JSON response (there are multiple types as different requests are needed to receive all needed information (Flickr API):

{
"collections": {
    "collection": [
        {
            "id": "122388635-72157643471284884",
            "title": "Test Gallery 2",
            "description": "Test 2",
            "iconlarge": "/images/collection_default_l.gif",
            "iconsmall": "/images/collection_default_s.gif",
            "set": [
                {
                    "id": "72157643471292484",
                    "title": "Set 1",
                    "description": ""
                }
            ]
        },
        {
            "id": "122388635-72157643469075734",
            "title": "Test Gallery 1",
            "description": "Bing Photos",
            "iconlarge": "http://farm3.staticflickr.com/2888/cols/72157643469075734_b9a37df67c_l.jpg",
            "iconsmall": "http://farm3.staticflickr.com/2888/cols/72157643469075734_b9a37df67c_s.jpg",
            "set": [
                {
                    "id": "72157643469056814",
                    "title": "Test Gallery 1",
                    "description": "Bing Backgrounds"
                }
            ]
        }
    ]
},
"stat": "ok"
}

So how do I pass the received data to other functions without a disruption in the data?

Herith12
  • 69
  • 8

1 Answers1

0

Code should be much like below

      success: function (collections)
      {
     $.each(collections,function(index,item){
        var i=0;
        $.each(item.conllection[i],function(index,item){
        alert(item.id);
        i++;
        });
        });
Mir Gulam Sarwar
  • 2,588
  • 2
  • 25
  • 39