When a user clicks a button I want to return some data and iterate through the JSON so that I can append the results to a table row.
At this point I am just trying to get my loop to work, here’s my code.
My JSON is coming back as follows: {“COLUMNS”:[“username”,”password”],”DATA”:[[“foo”, “bar”]]}
$("#button").click(function(){
$.ajax({
url: 'http://localhost/test.php',
type: 'get',
success: function(data) {
$.each(data.items, function(item) {
console.log(item);
});
},
error: function(e) {
console.log(e.message);
}
});
});
I’m getting a jQuery (line 16, a is not defined) error. What am I doing wrong?
Assuming your
JSONis like thisYou can query it like this
Sample : http://jsfiddle.net/4HxSr/9/
EDIT : As per the JSON OP Posted later
Your
JSONdoes not have an items, so it is invalid.As per your JSON like this
You should query it like this
Working sample : http://jsfiddle.net/4HxSr/19/