When trying to call the show_Message function, I expected an alert box to appear. However, the onreadystatechange is not working as expected. All other alert boxes are functioning properly.
Below is my JavaScript function:
function send_Message(){
var msg=document.getElementById("msg").value;
if(msg.length===0||msg===""){
alert("please enter some message");
return;
}
var sender=document.getElementById("username").value;
var sendto=document.getElementById("chat_id").options[document.getElementById("chat_id").selectedIndex].value;
alert(sender+" "+sendto);
var xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function(){
alert('hello');
if(xhttp.readyState==4 && xhttp.status==200){
document.getElementById("chat_logs").innerHTML=xhttp.responseText;
}
xhttp.open('GET','send_messages.php?sender='+sender+'&sendto='+sendto+'&message='+msg,true);
xhttp.send(null);
}
}