I worked on this for hours and I wasn't able to find a solution on your site. I have a jsonTable.php who connect to database and return a Json by echo:
{
"livres": [{
"titre": "John",
"auteur": "Doe",
"annee": "1989"
},{
"titre": "Anna",
"auteur": "Smith",
"annee": "1989"
},{
"titre": "Peter",
"auteur": "Jones",
"annee": "1989"
}]
}
The JQuery code I use is simple, it's:
$.ajax({
url: 'jsonTable.php',
type: 'GET',
dataType : 'json',
/*data: {
json: jsonData
},*/
success: function (response) {
alert(response);
console.log(response);
var trHTML = '';
$.each(response, function (item) {
trHTML += '<tr><td>' + item.titre + '</td><td>' + item.auteur + '</td><td>' + item.annee + '</td></tr>';
});
$('#records_table').append(trHTML);
}
});
The problem is it's doesn't work and return the error:
Uncaught TypeError: Cannot use 'in' operator to search for '179' in {"livres":[
{"titre":"John", "auteur":"Doe", "annee":"1989"},
{"titre":"Anna", "auteur":"Smith", "annee":"1989"},
{"titre":"Peter", "auteur":"Jones", "annee":"1989"}
]}
Strangely I didn't find that much example and I can solve it by my self.