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"}]}
resultisn’t an array.result.keyis an array. Also your field’s property ismessage, notMESSAGE: