Actually this is first time to implement Ajax in drupal. I would like to implement a user name validation using Ajax in user register section. When a user enter his name and filling another field, then validation is running and if the user name already existing in the system, then a error message shows, the user name is already taken. I used to call the Validation function on "blur" event of Jquery. The Jquery cod is below

$.post(Drupal.settings.basePath + "username_checking",{user_name:$(this).val()} ,function(data)
if(data=='no') //if username not avaiable
        $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
          //add message and change the class of the box and start fading
          $(this).html('<img align="absmiddle" src="images/Error.png" /> Username Not Available...').show().fadeTo(1900,1);

and I implemented the function in a hook menu as below,

    $items['username_checking'] = array(
'title' => 'username_availability',
'page callback' => 'username_availability',
'access arguments' => array('access caubo_registration content'),

and function is here

function username_availability() {
$user_name = $_POST['user_name'];
$select = "SELECT name FROM name WHERE user_name='%s' LIMIT '%d'";
$result = db_query($select,$user_name,1);   
$node = db_fetch_object($result);
if($node->name = $user_name){
  return "yes";
  return "no";

It shows the error in Firebud

POST http://localhost/WC/drupal_website/username_checking
403 Forbidden

I want to confirm is my method is right or not ? If right please solve the problem, or give the exact way to do.

2 Answers 2


if this is a registration function for anonymous users do they have the respective access caubo_registration content permission set in User Permissions?


you might want to take a look how username_check implemented the ajax call or even use that module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.