extracting data being returned from PHP script
Here is what I'm trying to do. I will pass a directory to a PHP script, that script will then return an array of filenames back to the javascript that called it. In the javascript I want to take the filenames returned and create links to them in an unordered list.
The PHP code to get the filenames is done and when I run the script I get an array that I have formatted into json... an example of the encoded array is as follows...
{"filename:["file01.jpg","file02.jpg","file03.jpg","file04.jpg","file05.jpg","file06.jpg"]};
So here is the jquery I'm trying to use to get the filenames and create my links... But I must be missing something because my variable... data ... is empty... but status is Success.
-
$.getJSON(url,function(data, status){
var returnData = JSON.stringify(data);
$.each(data,function(i,filename){
listElement = "<li><img src=\"" + directory + filename + "\" title=\"A caption 1\" alt=\"Image01\"></li>";
$('.gallery').append(listElement);
});
});
What am I missing here? I can't figure it out... am I not accessing the filename variable correctly?
Thanks for looking at this.
Bryce