Afternoon
My php and Ajax is now almost complete, but I'm stuck on one thing I'm getting the data sent back through to the ajax but its only showing [object Object] in the div I've specified and I'm wanting the number of results sent back to be in there.
<? $call="SELECT * FROM notifications WHERE notification_targetuser='$user1_id' ORDER BY notification_id DESC LIMIT 1";
$chant=mysqli_query($mysqli,$call) or die(mysqli_error($mysqli));
$num=mysqli_num_rows($chant);
while($notification_id=mysqli_fetch_array($chant))
{
?>
<script type="text/javascript">
setInterval(function(){
var notification_id="<?php echo $notification_id['notification_id'] ;?>"
$.ajax({
type: "GET",
url: "viewajax.php?notification_id="+notification_id,
dataType:"json",
cache: false,
success: function(response){
$("#mes").prepend(response);
}
});
},20000);
</script>
<? }?>
Vuewajax.php
<?php
include"database.php";
if(isset($_GET['notification_id'])){
$id=$_GET['notification_id'];
$user1_id=$_SESSION['id'];
$json = array();
$com=mysqli_query($mysqli,"select notification_id from notifications where notification_id > '$id'");
echo mysqli_error($mysqli);
$num = mysqli_num_rows($com);
if($num>0){
echo '<span id="mes">'.$num.'</span>';
}
$resultArr = mysqli_fetch_array($com);
$json['notification_id'] = $resultArr['notification_id'];
mysqli_free_result($com);
echo json_encode($json);
}
?>
My returned response in firebug
<span id="mes">1</span>{"notification_id":"3306"}