I have the following code:
$.ajax(
{
type: 'GET',
url : "chat/updates/",
async : true,
cache : false,
success: function(data){
if(data.success){
alert(data)
thread = data.messages;
senders = data.senders;
$.each(thread, function() {
if($("#chat-box").is(":visible")){
chatbuddy = $("#chat_buddy_id").val();
if(this.sender == chatbuddy){
li = '<li class="'+ this.type +'"><img src="assets/images/thumbs/'+this.avatar+'" class="avt img-responsive">\
<div class="message">\
<span class="chat-arrow"></span>\
<a href="javascript:void(0)" class="chat-name">'+this.name+'</a> \
<span class="chat-datetime">at '+this.time+'</span>\
<span class="chat-body">'+this.body+'</span></div></li>';
$('ul.chat-box-body').append(li);
$('ul.chat-box-body').animate({scrollTop: $('ul.chat-box-body').prop("scrollHeight")}, 500);
//Mark this message as read
$.ajax({ type: "POST", url: base + "chat/mark_read", data: {id: this.msg}});
}
else{
from = this.sender;
$.each(senders, function() {
if(this.user == from){
$(".chat-group").find('span[rel="'+from+'"]').text(this.count);
}
});
}
}
else{
from = this.sender;
$.each(senders, function() {
if(this.user == from){
$(".chat-group").find('span[rel="'+from+'"]').text(this.count);
}
});
}
});
var audio = new Audio('assets/notify/notify.mp3').play();
}
},
error : function(XMLHttpRequest, textstatus, error) {
console.log(error);
}
}
);
}, 2000);
method GET
is returning me the following JSON:
{"success":true,"messages":[{"msg":"57","sender":"2","recipient":"1","mensagem":"oi","time":"Nov 13, 2015, 6:17 pm","tipo":"receive","nome":""},{"msg":"58","sender":"2","recipient":"1","mensagem":"oi","time":"Nov 13, 2015, 6:18 pm","tipo":"receive","nome":""}],"senders":[{"user":2,"count":2}]}
but there in%% does not pass the check! Can anyone help me?