1
During page loading I take data from BD and create a list as below.
function chatContactList() {
$.post('src/inc/chat/', { DataProcess:'chatContactListShow' }, function(data){
switch(data.status) {
case 'error':
sNoty(data.message, null, 'error', null);
break;
case 'noHasList':
return false;
break;
case 'hasList':
var content = ''
$.each(data.chatOBJ, function(index, value){
content += '<li>';
content += ' <a href="#" data-process-id="'+value.pr_id+'" id="chatByContact" class="chatByContact">'+value.userName+'<i class="fa fa-comments"></i></a>';
content += '</li>';
});
$("#ulSidebarMenuContact").html(content);
break;
case 'logOut':
case 'reload':
window.location.reload();
break;
}
}, 'json');
};
After loading the data and creating the list, I need to take the data-process-id attribute, no event click, and do constant updating, but I don’t get any attributes.
function updateMessageNotRead()
{
var prIdArray = new Array();
$('a[id="chatByContact"]').each(function() {
prIdArray.push($(this).attr('data-process-id'));
});
...
}
How to get this attribute created automatically and without delegating to event as click?
this function has to be executed within the return function that creates the list
– Wees Smith
Problem is that I need to update periodically if there is message regarding this contact using the information from li
– RRV
and how do you intend to do this periodic update? setInterval?
– Wees Smith
Set with setinterval
– RRV
But it will be in the same scheme, will run the setInterval on the return of the function
– Wees Smith
I have 2 functions, the first that generates the chat contact list, when the function receives the JSON, generates the li.. You say that when you finish generating the read I call the function to update the messages?
– RRV
Let’s go continue this discussion in chat.
– Wees Smith
Wees, I just called the function to check the message, and set the setinterval, and it worked successfully.
– RRV