Hello I am trying to create a notification badge. Every time a new item is added to my list the badge counter will add one. I have started a code but the results are not the expected.
function buildBadge () {
var badgeContainer = document.getElementById('services');
//Create counter
var counter = document.createElement('div');
counter.setAttribute('id', 'counter');
counter.classList.add('counter');
var counterText = document.createElement('p');
counterText.setAttribute('id', 'counterText');
badgeContainer.appendChild(counter);
counter.appendChild(counterText);
}
buildBadge();
var count = ' ';
function changeCounter() {
count++;
var newCounterText = count;
counterText.innerHTML = newCounterText;
}//end changeCounter function
changeCounter();
function send(){
$.ajax({
url: "http://bc-net/Sandbox/juandev/_api/web/lists/GetByTitle('Qlinks')/items",
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data) {
var items = data.d.results;
console.log(items);
//Send another request in 10 seconds.
setTimeout(function(){
send();
}, 10000);//End setTimeout
}
});//end ajax call
}//end send function
//Call our function
send();