Pergunta

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?

Foi útil?

Solução

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);
                }); 

Outras dicas

Try This

$.each(rf.files,function(index,file){
 attractionImgLinks.push(file.url);
})
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top