我在从数据库中检索图像位置时遇到问题并使用ajax显示它。 下面是代码。 我可以检索除图像之外的所有数据。 需要帮助。
<script type="text/javascript">
$(document).ready(function() {
var url = "http://localhost/project/app/read.php";
$.getJSON(url, function(result) {
console.log(result);
$.each(result, function(i, field) {
var id = field.id;
var bookname = field.bookname;
var publisher = field.publisher;
var author = field.author;
var location = field.location; //image location
$("#listview").append("<h2>" + bookname + " </h2><p>" + publisher + "</p><p>" + author + "</p>");
});
});
});
</script>
read.php
<?php
include "db.php";
$data=array();
$q=mysqli_query($con,"select * from `book`");
while ($row=mysqli_fetch_object($q)){
$data[]=$row;
}
echo json_encode($data);
?>
以下代码也无效
"<img src=" +location+ /">"