I'm trying to build an app that gets data from server with getJSON and then alerts the row. This is the code I use but it doesn't show the row from JSON, it just says "undefined". What could be the reason for this?
$(document).ready(function(){
$("button").click(function(){
$.getJSON("MyURL/test.php",function(result){
$.each(result, function(i, field){
alert(field.MESSAGE);
});
});
});
});
This is the JSON response:
{"key":[{"message":"test"}]}
result isn't an array. result.key is an array. Also your field's property is message, not MESSAGE:
$.each(result.key, function(i, field){
alert(field.message);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With