Skip to content
Advertisement

Uncaught ReferenceError: xmlhttp is not defined?

JavaScript

When I run the following HTML page in the Google Chrome Browser via Netbeans, I am met with this error (see Title) when I try to select a person from the list.

xmlhttp.onreadystatechange = function()

This line of code and the one below seems to be the areas of concern based on Chrome’s Developer tools.

select name=”users” onchange=”showUser(this.value)

Can anyone pinpoint what needs to be changed?

Advertisement

Answer

Right underneath:

JavaScript

Add:

xmlhttp = new XmlHttpRequest();

That way, you’ll satisfy web browsers with javascript engines that have XMLHttpRequest defined.

Also, xmlhttp needs to have a valid value (handle) before xmlhttp.onreadystatechange = function() can be properly executed.

If your browser (especially very old IE browsers) is still picky then change xmlhttp to var xmlhttp since var before a variable name means to define a new variable.

Advertisement