I am trying to return HTML through $.ajax
, this is my code:
$(document).ready(function() {
$(".click").on('click',function() {
var id= $(this).attr("data-id");
$.ajax({
type: "POST",
url: "getevents.php",
data: {id:id},
dataType: "html",
success: function(response){
alert(response);
$('.headimg').html(response);
}
});
})})
My PHP code:
$singleevent = mysqli_query($link, "SELECT `content` FROM `events` WHERE `id`
= $id") ;
if(!$singleevent){
echo mysqli_error();
}
else {
$result = mysqli_fetch_array($singleevent);
echo $result;
}
Link to be clicked:
<a class='click' data-id='<?=$rows["id"];?>'><?=$rows['title'];?></a>
In alert() this is what I get Array
If I do print_r() instead of echo this is what I get
[0] => <div class='row'>
<div class='col-sm-12'>
<img src='img/img.png' class='img-responsive'>
</div>
<div class='col-xs-12'>
<p> October 14th | All Day</p>
</div>
</div>
[content] => <div class='row'>
<div class='col-sm-12'>
<img src='img/img.png' class='img-responsive'>
</div>
<div class='col-xs-12'>
<p> October 14th | All Day</p>
</div>
</div>
How to I put it in HTML rather than array?