[英]jQuery no alert array data
{"autor":"Testando","publication":"a"}{"autor":"Testando","publication":"a"}{"autor":"Testando","publication":"asa"}{"autor":"Testando","publication":"a"}
PHP; PHP;
header('Content-Type: application/json');
while ($rows = $stmt->fetch(PDO::FETCH_ASSOC)) {
$autor = $rows['Nome'];
$publication = $rows['publication'];
$my = array(
"autor"=>"$autor",
"publication"=>"$publication"
);
echo json_encode($my);
}
dataType: "json",
success: function (data) {
$(data).each(function(autor, pubication) {
alert(data.autor + " : " + data.publication)
});
}
My problem: jQuery no alert the data
我的问题:jQuery没有警报数据
I think the problem is because there is no comma between the results, because when there is only one result, he warns normally in the future want to make a .append in the data, but I can not simply alert data, can anyone help?
我认为问题是因为结果之间没有逗号,因为当只有一个结果时,他通常会在以后警告要在数据中添加.append,但是我不能简单地提醒数据,有人可以帮忙吗?
The problem is exactly what you said. 问题就是你所说的。 Try to do this:
尝试这样做:
header('Content-Type: application/json');
$arr = array();
while ($rows = $stmt->fetch(PDO::FETCH_ASSOC)) {
$autor = $rows['Nome'];
$publication = $rows['publication'];
$my = array(
"autor"=>"$autor",
"publication"=>"$publication"
);
$arr[] = $my;
}
echo json_encode($arr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.