M Argus Chopin Gyver M Argus Chopin Gyver - 1 month ago 8
Ajax Question

Append img from AJAX

I'm trying

append
<img>
to a
div
using Ajax (because I need to fetch the name of image from database).

I already get the
<img>
tag on my
div
, also get the
src
attribute to the correct image. But I'm still not seeing the image. I'm just seeing a
<img>
tag with 0 x 0 size. Try to enlarge the size, still see nothing..

I try to open image via link that generated inside
src
attribute, and I can see the image that I want to append..
Why this is happen ?

This is my code

Trigger to function that contain ajax

<div class="HotelListDescriptionContent" onclick='showDetailRoom("<?php echo $arrayroomssearch[$arrk]['room_code']?>")'>


Function With Ajax

function showDetailRoom(roomid)
{
if(j("#detailroom"+roomid).is(":visible"))
j("#detailroom"+roomid).hide();
else
{
j.post("inc/querys/roomdetail.php",
{
roomid : roomid,
},
function(data){
// console.log(data);
j("#detailroom"+roomid).html("");
// j("#detailroom"+roomid).append($("<option></option>").append("Select your state..."));
if(data == "empty")
{
j("#detailroom"+roomid).append($("<option></option>").append("State Not Found..."));
}
else
{
j(data.photo).each(function(i,item){
// console.log(item);
j("#detailroom"+roomid).html("<img scr='<?php echo SITE_URL;?>upload_photos/images/"+item+"'/>");
})
}
j("#detailroom"+roomid).show();
},
"json");
}
}


Div target

<div id="detailroom<?php echo $arrayroomssearch[$arrk]['room_code'];?>" style="display:none;">


Div target (via Inspect Element)

<div id="detailroom20" style=""><img scr="http://localhost/bookingbeol/bk-admin/upload_photos/images/kamar3-1476346812.jpg"></div>


Div target not showing the image
enter image description here

Answer

Got it-- you just mistyped it -- should be src not scr. Easy mistake to make-- difficult to see or notice when scanning or glancing over the code.

Comments