【发布时间】:2016-05-14 04:29:32
【问题描述】:
我为此工作了几个小时,但无法在您的网站上找到解决方案。我有一个连接到数据库并通过回显返回 Json 的 jsonTable.php:
{
"livres": [{
"titre": "John",
"auteur": "Doe",
"annee": "1989"
},{
"titre": "Anna",
"auteur": "Smith",
"annee": "1989"
},{
"titre": "Peter",
"auteur": "Jones",
"annee": "1989"
}]
}
我使用的jQuery代码很简单,就是:
$.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);
}
});
问题是它不起作用并返回错误:
未捕获的类型错误:无法使用 'in' 运算符在 {"livres":[
中搜索 '179' {"tire":"John", "auteur":"Doe", "annee":"1989"},
{"titre":"Anna", "auteur":"Smith", "annee":"1989"},
{“标题”:“彼得”,“作者”:“琼斯”,“安妮”:“1989”}
]}
奇怪的是我没有找到那么多例子,我可以自己解决。
【问题讨论】:
-
提供jsonTable.php的代码
-
response = $.parseJSON(response);
标签: php jquery mysql json ajax