I'm having some problems while performing an ajax request by javascript, however, it does appear that the variable xmlhttp
has not been defined, even though I set it before the function and before using it. How to solve?
var xmlhttp;
function generateMessage(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = callbackChampMessage();
var url = "randomName.php";
xmlhttp.open("GET", url, true);
xmlhttp.send();
};
function callbackChampMessage(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
var messageHeader = document.querySelector("#champ-message");
champMessage.innerHTML = xmlhttp.responseText;
};
};
- Given a console.log (xmlhttp) I get the values all zeroed or null