Ok. So I have a PHP function that is supposed to be sending back a customized string that the AJAX will interpret and automatically update/select an option in a select menu. The problem I am running into is that the AJAX isn't receiving anything (or it would seem). Not sure if I am completely overlooking something or if my code just sucks. I will post the particulars below.
//PHP code sending the string out....
Now, the database updates each time, but the alerts NEVER fire because the response is always blank. Any ideas?
//PHP code sending the string out....
Code:
$newMake = strtolower($_REQUEST['make']);
$query = "SELECT * FROM make";
$result = mysql_query($query)or die($query." -- ".mysql_error());
$bool = true;
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
if(strtolower($row['Name']) == $newMake)
{
$bool = fasle;
}
}
if($bool)
{
$newMake = ucfirst($newMake);
$query = "INSERT INTO make (Name) VALUES ('$newMake')";
$result = mysql_query($query)or die($query." -- ".mysql_error());
if($result)
{
$query = "SELECT * FROM make WHERE Name = '$newMake'";
$temp = mysql_query($query)or die($query." -- ".mysql_error());
$row=mysql_fetch_array($temp, MYSQL_ASSOC);
}
echo "True,".$newMake.",".$row['makeID'].",MAKE"; //<-- THIS PART
}
else
echo "False";
//Javascript handling the return....
function insert(url)
{
var request;
request = getHTTPObject();
request.onreadystatechange=function()
{
if(request.readyState == 4)
{
if(request.responseText == "")
{
alert("Son of a....");
}
else
{
response = request.responseText;
alert(response);
response = response.split(",");
if(response[0] == "True" && response[3] == "MAKE")
{
var select = document.getElementById('makeList');
var option = document.createElement('option');
option.text = response[1];
option.value = response[2];
option.selected = true;
select.add(option, null);
sendRequest(document.getElementById('modelList'), 'loadMake.php?id='+option.value);
alert("Added "+response[1]+" to database.");
}
}
}
else if(request.readyState == 1)
{
//waiting...
}
}
request.open("POST",url,true);
request.send(null);
}
Comment