I need helps to retrieve my images that are uploaded to my database to show up in my HTML. It would be appreciated if anyone could help me.
Here is my Ajax code.
$(document).ready(function() {
$.ajax({
url:"../controller/image.php",
dataType:"json",
type:"POST",
data:{
method:"getall"
},
success: function(resp) {
console.log(resp);
for(var i = 0; i<resp.length; i++){
var img = document.createElement("img");
var div = document.createElement("div");
var h = document.createElement("h4");
img.innerHTML = img.src + ":"+resp[i].title;
img.onclick = function() {
console.log(resp);
}
}
}
});
});
Here is my PHP code.
function getall() {
global $db;
$query = "SELECT * FROM images";
$result = $db->query($query);
$row = $result->fetchAll();
echo json_encode($row);
}
I have my images loaded to my database and I can see that they are their with the console.. but not being able to see them. Thank you.