AJAX call as follows:
$.get('file.php')
.done(function(data) {
console.log(data);
});
Console returns:
[{"0":"PS001","code":"PS001"}]
However if amend the log to console.log(data.code)
it returns undefined
. Also, traversing JSON using each
as such:
.done(function, data) {
$.each(data, function(key, value) {
console.log(value.code);
});
)};
results in the following error:
[Error] TypeError: [{"0":"PS001","code":"PS001"}] is not a valid argument for
'in' (evaluating 'b-1 in a')
JSON looks well-formed, so not sure what the issue is?