I'm just adding a brand new feature to my Joomla TPJOBS component although it's a badOrtotalOrenergetic component but simply I am adding a person title Availability checker nevertheless its no longer working since it might be because of within this component.

Look into the website : http://tinyurl.com/72rx7af

[Click Check availability which isn't working]

My Joomla Component Directory is : public_htmlcomponentscom_tpjobs

You will get the files here http://forum.joomla.org/download/file.php?id=88705

Editing tpjobs.html.php(exiting) and username_validate.php (produced)

My Javascript AJAX Code : that is under tpjobs.html.php

<script type="text/javascript">
        <!--
  //function to create ajax object
  function pullAjax(){
    var a;
    try{
      a=new XMLHttpRequest()
    }
    catch(b)
    {
      try
      {
        a=new ActiveXObject("Msxml2.XMLHTTP")
      }catch(b)
      {
        try
        {
          a=new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch(b)
        {
          alert("Your browser broke!");return false
        }
      }
    }
    return a;
  }

  function username_validate()
  {
    site_root = '';
    var x = document.getElementById('username');
    var msg = document.getElementById('msg');
    user = x.value;

    code = '';
    message = '';
    obj=pullAjax();
    obj.onreadystatechange=function()
    {
      if(obj.readyState==4)
      {
        eval("result = "+obj.responseText);
        code = result['code'];
        message = result['result'];

        if(code <=0)
        {
          x.style.border = "1px solid #FF0084";
          msg.style.color = "#FF1A00";
        }
        else
        {
          x.style.border = "1px solid #008C00";
          msg.style.color = "#73880A";
        }
        msg.innerHTML = message;
      }
    }
    obj.open("GET",site_root+"username_validate.php?username="+user,true);
    obj.send(null);
  }
  //-->
</script>
<style>
#username{border: 1px solid #000;}
</style>

PHP File underneath the TPJobs component

<?php
    defined('_JEXEC') or die('Restricted access');


    $user = strip_tags(trim($_REQUEST['username']));

    if(strlen($user) <= 0)
    {
      echo json_encode(array('code'  =>  -1,
      'result'  =>  'Invalid username, please try again.'
      ));
      die;
    }

    $db =& JFactory::getDBO(); //get database object
    $db->setQuery("Select username FROM #__users where username = '$user'")

    $db->query(); //do actual query

    $result = $db->getAffectedRows(); //return affected rows

    if($result)
    {
      echo json_encode(array('code'  =>  1,
      'result'  =>  "Success,username $user is still available"
      ));
      die;
    }
    else
    {
      echo  json_encode(array('code'  =>  0,
      'result'  =>  "Sorry but username $user is already taken."
      ));
      die;
    }
    die;
?>

you will find two problems that i notice

first one is your ajax url does not appears to become correct. component folder title is com_tpjobs as well as in your url it's components/tpjobs it ought to be components/com_tpjobs/.....

second point is the fact that while calling personal files directly through ajax it does not load joomla framework which means you cannot use joomla class and processes inside it.

to obtain this you need to include couple of line towards the top of your ajax file see here How to extend Joomla! to my custom PHP file