onreadystatechange is a PROPERTY (event handler) of XMLHttpRequest, not a method. You assign a function to it: xhr.onreadystatechange = function() { ... }. It's called when the readyState changes, but you don't invoke it as a method like xhr.onreadystatechange().