Hello all - I am trying to do what I thought would be simple Ajax function. I am trying to compare what is in a text box to what is retrieved from a mysql table, but I can not get the js to read the response given from my php page. It is blank. Here is my code. Thanks ahead of time.
***JS***
function fields(){
email=document.add.email.value;
if (email!=''){
alert('init!');
var httpObject=getHttpObject();
if (httpObject==null){
alert ("Your browser does not support AJAX!");
return false;
}
var url="/map/ppmap/users/getEmail.php";
url=url+"?e="+email;
alert(url); //this is working
httpObject.onreadystatechange=function(){state_Change(httpObject);}
httpObject.open("GET",url,true);
httpObject.send(null);
}
}
function state_Change(httpObject){
if (httpObject.readyState==4){
alert(httpObject.responseText);//no response
if(httpObject.responseText==0){
alert('1'+httpObject.responseText);//no response
return true;
}else{
alert('2'+httpObject.responseText);
document.getElementById('emailAdd').innerHTML = httpObject.responseText;
return false;
}
}
}
function getHttpObject(){
if (window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest){
return new XMLHttpRequest();
}else {
alert("Your browser does not support AJAX.");
return null;
}
}
***PHP***
$query="SELECT email FROM bw_users_users";
$eAdd = $gBitUser->pp_exec_sql($query);
$eArray=array();
$e=$_GET['e'];
for($j=0; $j<count($eAdd); $j++){
foreach(array_keys($eAdd[$j]) as $myKey){
array_push($eArray, $eAdd[$j][$myKey]);
}
if ($e==$eAdd[$j])
{
echo "Email address already exists. Please enter a different email address";
}else{
echo "0";
}
}
***JS***
function fields(){
email=document.add.email.value;
if (email!=''){
alert('init!');
var httpObject=getHttpObject();
if (httpObject==null){
alert ("Your browser does not support AJAX!");
return false;
}
var url="/map/ppmap/users/getEmail.php";
url=url+"?e="+email;
alert(url); //this is working
httpObject.onreadystatechange=function(){state_Change(httpObject);}
httpObject.open("GET",url,true);
httpObject.send(null);
}
}
function state_Change(httpObject){
if (httpObject.readyState==4){
alert(httpObject.responseText);//no response
if(httpObject.responseText==0){
alert('1'+httpObject.responseText);//no response
return true;
}else{
alert('2'+httpObject.responseText);
document.getElementById('emailAdd').innerHTML = httpObject.responseText;
return false;
}
}
}
function getHttpObject(){
if (window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest){
return new XMLHttpRequest();
}else {
alert("Your browser does not support AJAX.");
return null;
}
}
***PHP***
$query="SELECT email FROM bw_users_users";
$eAdd = $gBitUser->pp_exec_sql($query);
$eArray=array();
$e=$_GET['e'];
for($j=0; $j<count($eAdd); $j++){
foreach(array_keys($eAdd[$j]) as $myKey){
array_push($eArray, $eAdd[$j][$myKey]);
}
if ($e==$eAdd[$j])
{
echo "Email address already exists. Please enter a different email address";
}else{
echo "0";
}
}