Valid JSON Array logs Undefined to the console no matter what I do
I'm using Jquery to call a php script which then generates an array. I'm using
echo json_encode (array ( "key"=>$value, "key"=>$value, "key"=>$value ));
As the last line of the PHP document which is generating a valid JSON array. I checked via Firebug. Unfortunately when I try to access one of the values with dot-notation, it's coming up as undefined.
$.ajax({
type : "POST",
cache : false,
url :开发者_StackOverflow社区 "/generateArray.php",
data : { data: $(this).attr('id') },
success: function(data) {
console.log(data.key);
}
This is outputting "undefined" to the console, even though when I check the JSON output the array is valid.
I have no idea how to even begin debugging what's wrong with my code. Please help!
Are you sure data
is being json decoded
on the Javascript side and isn't just a String
?
精彩评论