AJAX responseText is undefined after GET request to .php

I’m trying to pull a list of devices from a mySQL db, which I then format into an html select/option element in my .php and then I echo the string of html to insert into my main page, but it won’t return the string I echo to the responseText.Here’s my .php:<?php<br />…

via PHP Website Development » Search Results » ajax:

AJAX responseText is undefined after GET request to .php

I’m trying to pull a list of devices from a mySQL db, which I then format into an html select/option element in my .php and then I echo the string of html to insert into my main page, but it won’t return the string I echo to the responseText.
Here’s my .php:
$dbhost = “localhost”;
$dbuser = “root”;
$dbpass = “admin”;
$dbname = “devices”;
//Connect to MySQL Server
$con=mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());

$sql=”SELECT DISTINCT device_name FROM device_graphs”;
$result=mysql_query($sql, $con);

$responsetxt=”Hello all :) ”;
$counter=0;
while($row = mysql_fetch_array($result))

$responsetxt .= “

“;
$counter++;

echo $responsetxt;

?>I’m trying to generate a dropdown list of device names based on the devices listed in my db. When i open just the .php file in my browser it echoes correctly.
function deviceDropdown(monNum, insideHTML)

var ajaxRequest; // The variable that makes Ajax possible!
try
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
catch (e)
// Internet Explorer Browsers
try
ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
catch (e)
try
ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
catch (e)
// Something went wrong
alert(“Your browser broke!”);
return false;

}
}
ajaxRequest.onreadystatechange = function()
if(ajaxRequest.readyState == 4)
alert(ajaxRequest.responseText);
ajaxresponse = ajaxRequest.responseText;
alert(ajaxresponse);
deviceDropdown_pt2(monNum, ajaxresponse, insideHTML);

}
ajaxRequest.open(“GET”, “device_list.php”, true);
ajaxRequest.send(null);
}ajaxresponse is undefined everytime I try this; it just pops up 2 empty javascript alert boxes. If I run just the .php in my browser I get the correct output echoed to my window, so I don’t think it’s a problem with the php unless there’s a problem passing html via php through ajax.
Here’s the rest of the dropdown code:
function deviceDropdown_pt2(monNum, ajaxresponse, insideHTML)

//Sets the action to occur when a selection is made in the device dropdown,
// in this case the properties dropdown menu
insideHTML=insideHTML + “

“;
My main .js has the following defined var iframe=document.getElementById(“bdy”); and:
insideHTML=”

“;
insideHTML=insideHTML + “

“;
insideHTML=insideHTML + “

“;
iframe.innerHTML=insideHTML;
…………………………………..

You should use http://jquery.com/
simple example for what you want to achieve:
$.get(‘ajax/test.html’, function(data)
$(‘.result’).html(data);
alert(‘Load was performed.’);
);and all you have to do is include this in your header: