Hi there! I'm struggling with a simple code issue. The problem is that the function assigned to onreadystatechange never seems to be executed. I added an alert to display the readyState and status of xmlhttp, which both showed as 1 and 0 respectively. I'm baffled as to why the state isn't changing, especially since everything else in the code seems to be working fine. I even used alert boxes to confirm that the username being fetched from the form displays correctly. Can someone please help me out here? I'm really stuck...
function checkAvailability() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp) {
var regform = document.getElementById("regform");
var username = regform.username.value;
xmlhttp.open("POST", "http://localhost:8080/UsernameAvailability", true);
xmlhttp.onreadystatechange = function() {
alert(xyz);
}
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("username=" + username.value);
}
}