Here is my JavaScript code:
$('check_username').addEvent('click', function(e) {
var req = new Request({
url: 'Namecheck.php?name='+$('user_name').get('value'),
method: 'post',
onRequest: function() { alert('Namecheck.php?name='+$('user_name').get('value')); },
onComplete: function(response) { alert('The response is the following : ' + response); },
onSuccess: function(txt){
if(txt=="Success"){
$('avail_status').set('html','Username is available.');
}else{
$('avail_status').set('html','Username is not available ,'+txt);
}
},
onFailure: function(){
alert("Failed!! Please try again.");
}
});
req.send();
});
and my PHP code :
require_once('../include/DebugLog.class.php');
DebugLog::getInstance()->Debug('NAMECHECK : Checking name'.$_REQUEST["name"]);
$name=isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
$flag=false;
if(($name=="")||($name==null)){
DebugLog::getInstance()->Debug('NAMECHECK : No Username specified');
echo "No Username specified";
exit;
}
else{
require('../include/LoginSystem.class.php');
$myObj=new LoginSystem();
$sql="select * from client_info where binary UserName ='".$name."' AND CreatedBy=0 ";
$result=$myObj->run_sql($sql);
if($result!=false){
$row = mysql_fetch_assoc($result);
if($row['UserName']==$name){
DebugLog::getInstance()->Debug('NAMECHECK : Name already exists !!');
echo "Already exists!!";
exit;
}
else{
DebugLog::getInstance()->Debug('NAMECHECK : Name does not exists !!');
echo "Success";
exit;
}
}else{
DebugLog::getInstance()->Debug('NAMECHECK : Query failed ,$sql: '.$sql);
echo "Try Again!!";
exit;
}
}
When the Ajax request is made, the PHP code is executed properly but with my JavaScript, I get a "undefined" response.