xmlhttp.onreadystatechange=function() {
So this says onreadystatechange, invoke function(). Can I put parameters in function()? Second question, what does it mean when someone writes, xmlhttp.onreadystatechange=statechanged? Does that mean it will always be true or something?
You can’t use a parameter since
onreadystatechangehas no parameters to give you. What parameter are you expecting? It is simply a hook for handling the response. What you do have available is thexmlhttp.readyStatewhich tells you if the response is ready or not,xmlhttp.status– the http status code (i.e. 200), andxmlhttp.responseText– the response itself.No – that means you are assigning a variable reference (a function) to
onreadystatechange.I would strongly suggest using a JS framework (such as jQuery) to do AJAX calls – it will abstract away the low-level details you are asking about. If you must use native JS AJAX calls – read this tutorial.