You receive data asynchronously. The callback function (data) {} is called after getPicsInFolder .
You have two options:
One way to do this is to pass the callback to getPicsInFolder , for example:
function getPicsInFolder(folder, callback) { return_data = "error"; $.get("getpics.php?folder=" + folder, function (data) { data = jQuery.parseJSON(data); $.each(data, function (index, value) { data[index] = "folders/" + folder + "/" + value; }); callback(data);
Then, when you call your getPicsInFolder, instead:
pics = getPicsInFolder('foldername'); //do something with pics
do the following:
getPicsInFolder('foldername', function (pics) {
Skilldrick
source share