I am new to javascript and especially to ajax..And just trying to figure it out..
i wrote this code from one tutorial and can't find what i did wrong. Here you can see it live
The error i am getting from Firebug: "TypeError: xmlhttp is undefined [Break On This Error]
if (xmlhttp.readyState == 4){"
my code is
// JavaScript Document
var xmlhttp;
var url;
function ajaxFunction(){
if (window.ActiveXObject){//if the window is InternetExplorer
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){// if Window is Firefox etc..
xmmlhttp= new XMLHttpRequest();
}else{
alert ("Get a New Browser")
}
}//end of ajaxFunction()
function getInfo(){
ajaxFunction();
var entryInfo= document.getElementById("entry").value;
function stateChanged(){
if (xmlhttp.readyState == 4){
document.getElementById("results").innerHTML = xmlhttp.responseText;
}//if (xmlhttp.readyState == 4)
}//end of function stateChanged()
url = "info.php?user="+entryInfo;
xmlhttp.onreadystateshange=stateChanged();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}// end of function getInfo
onreadystatechangeproperty should be a reference to the function without(), not the function call with()as inxmlhttp.onreadystateshange = stateChanged;