This is so basic but I have now been stuck for over an hour as I cannot find an exact example. Thanks for any links you can provide.
I build the JSON in php like this:
return json_encode(['error' => 'customer number not found']);
It returns a basic array that looks like this (from inspect):
{error: 'customer number not found'}
I have an Ajax/getJSON call via jQuery:
$.getJSON( url, function( response ) {
$.each(response[0], function(key, value) {
// Check response for errors
if (key == "error") {
// display message
$(message_area).innerHTML = value;
// Show the error message
$(message_area).show();
};
});
});
I just want to check the first value, then show the second and display the container. The above code gives me
Uncaught TypeError: Cannot read property 'length' of undefined