Greetings all. I would like to know if anyone here is fluent enough with javascript to be able to assist me in correcting a notification problem. I am attempting to use javascript to access an external php file to select a message count from various users in a database on intervals. I am able to get it to work if there is ONLY one user. However it does not work for more than one. My print_r() on the external php file does show all messages but the javascript apparently is the failure. I have tried to use
var elem = document.querySelectorAll(‘.counter’);
var elem_array = Array.prototype.slice.call(elem);
However, this did not show any data as it stated “undefined”.
My current javascript code is below which does work for only the first row of data from the database. If you need the external php file do not hesitate to ask. Thank you in advance.
function call_notification(elem) {
setInterval(function() {
var xml = new XMLHttpRequest();
xml.onreadystatechange = function() {
if(this.readyState == 4 || this.status == 200) {
const elem = document.querySelector('.counter');
elem.textContent = this.responseText;
console.log(elem.textContent);
}
};
xml.open("POST", "test.php", true);
xml.send();
}, 5000);
}
call_notification();