Reputation: 931
I am trying to store a list of value in an array using $.getJSON but somehow it's not working out the array shows undefined in console.log
here is my getJSON code
jQuery.getJSON(List6.attractionimg, function(rf){
jQuery.each(rf, function(index, file){
attractionImgLinks.push(file.url);
});
JSON code the url "List6.attractionimg" is giving
{"files":[{"name":"2013-11-17_183243.png","size":7975,"url":"http:\/\/example.com\/demo\/wp-content\/uploads\/rform\/attractionimg\/user5307eb38362d4\/2013-11-17_183243.png","thumbnailUrl":"http:\/\/example.com\/demo\/wp-content\/uploads\/rform\/attractionimg\/user5307eb38362d4\/thumbnail\/2013-11-17_183243.png","deleteUrl":"http:\/\/example.com\/demo\/wp-content\/themes\/driskill\/rform\/files\/attractionimg\/?file=2013-11-17_183243.png","deleteType":"DELETE"}]}
I am declaring the array outside this code is that the problem here?
Upvotes: 0
Views: 158
Reputation: 37520
The JSON is an object with a files
property that contains an array. Try looping the files
property of the result...
jQuery.getJSON(List6.attractionimg, function(rf){
jQuery.each(rf.files, function(index, file){
attractionImgLinks.push(file.url);
});
Upvotes: 1
Reputation: 895
Try This
$.each(rf.files,function(index,file){
attractionImgLinks.push(file.url);
})
Upvotes: 0