0

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?

2 Answers 2

1

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);
                }); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try This

$.each(rf.files,function(index,file){
 attractionImgLinks.push(file.url);
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.