I am trying to return a json array to a function and output the results. Here is a sample of what I want to achieve but 'thisArray' keeps coming up as 'undefined'. What am I doing wrong? Grateful for feedback...
<html>
<head>
<title>Test Array</title>
function recipesTestObject(recId, recipe)
{
this.recId = recId;
this.recipe = recipe;
}
function initialise() {
$.getJSON ("/mealplanners2/apprequests/mealplanner.php?action=getRecipesByCat", { recCategory: 2 }, function(json) {
var recipeTest = new Array();
$.each (json.recipes, function (){
recipeTest[recipeTest.length] = new recipesTestObject(this['id'], this['recName']);
});
return recipeTest;
});
}
function display(thisArray) {
for (var i=0; i < thisArray.length; i++) {
document.write("Name: "+thisArray[i].recipe+"<br>");
}
}
</script>
</head>
<body>
<script language="javascript">
var x;
x = initialise();
display(x);
</script>
</body>
</html>