【发布时间】:2015-07-16 08:34:17
【问题描述】:
我不确定如何通过 ajax JSON 将 mysql 查询的结果传递到 html 页面。 ajax2.php
$statement = $pdo - > prepare("SELECT * FROM posts WHERE subid IN (:key2) AND Poscode=:postcode2");
$statement - > execute(array(':key2' => $key2, ':postcode2' => $postcode));
// $row = $statement->fetchAll(PDO::FETCH_ASSOC);
while ($row = $statement - > fetch()) {
echo $row['Name']; //How to show this in the html page?
echo $row['PostUUID']; //How to show this in the html page?
$row2[] = $row;
}
echo json_encode($row2);
如何将上面的查询结果通过下面的ajax传递到html页面中显示?
我的 ajax
$("form").on("submit", function () {
var data = {
"action": "test"
};
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "ajax2.php", //Relative or absolute path to response.php file
data: data,
success: function (data) {
//how to retrieve the php mysql result here?
console.log(data); // this shows nothing in console,I wonder why?
}
});
return false;
});
【问题讨论】:
-
检查控制台中的网络标签。
-
@sgtBOSE,相关文件的状态显示正常
-
回应是什么?
标签: php jquery mysql ajax json