Your handling of the response must be from within the callback functions given to $.getJSON();
That is, the scope of the response object in the case of success is only within the success function. Put your success handling code in there (or call it from there) and you should be good to go.
For example:
function doSomethingWithSuccessResponse( response ){
console.log( response );
// Execute the rest of your success case logic here
}
$.getJSON('../_javascripts/array.php')
.success(function(response) { doSomethingWithSuccessResponse(response); })
.fail(function(jqXHR, status, error){ console.info(error); alert("error"); });
Or, more concisely:
function doSomethingWithSuccessResponse( response ){
console.log( response );
// Execute the rest of your success case logic here
}
$.getJSON('../_javascripts/array.php')
.success(doSomethingWithSuccessResponse)
.fail(function(jqXHR, status, error){ console.info(error); alert("error"); });
Similarly for the failure case - execute your failure handling logic within the failure callback.
It looks like your API is returning an object with embedded arrays:
Object {
P5yTZ947: Array[3],
11y6tdo8: Array[3],
66j8ttk2: Array[3],
27c7uqv0: Array[3],
44f6hvt7: Array[3]…
}
Use object-looping semantics to iterate through the object. Then use an inner loop to loop over the elements of the array:
for (var key in response) {
if (response.hasOwnProperty(key)) {
// key is now "P5yTZ947" or "11y6tdo8", etc
var innerArray = response[key];
// Loop over the values of the inner array
for( var i = 0; i < innerArray.length; i++ ){
console.log( innerArray[i] ); //
}
}
}