找不到JFactory

I made a external file in Joomla getuser.php and place it at administrator/getuser.php

contain db queries

<?php
$q=$_GET["q"];
$db = JFactory::getDBO();
// Create a new query object.
$query = $db->getQuery(true);
$query->select($db->nameQuote('product_name'));
$query->from('#__virtuemart_products_en_gb');
$query->where($db->nameQuote('virtuemart_product_id').' = '.$db->quote($q));
$db->setQuery($query);
$result = $db->loadResult();

  echo "<tr>";
  echo "<td>" . $result['product_name'] . "</td>";
  echo "</tr>";
?>

and call it from product_edit_information.php using ajax located at administrator/components/com_virtuemart/views/product/tpl/product_edit_information.php

code is

<form>
<select name="users" onChange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="7745">YA Ali</option>
<option value="7746">Qasim</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
<script>
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>

error is

Fatal error: Class 'JFactory' not found in C:\xampp\htdocs\bc22\administrator\getuser.php on line 3

what is the reason of this error how i add external files in joomla

i also go through this but cant understand... http://docs.joomla.org/Adding_AJAX_to_your_component

defined('_JEXEC') or die('Restricted access'); 

when i put this at top of getuser.php it will give me error

Restricted access

when i echo $q=$_GET["q"]; // output 7745 and 7746

 <option value="7745">YA Ali</option>
 <option value="7746">Qasim</option>

but after jFactory not found error occurred

Sorry for my poor English

you should add this code in top of your code:

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

if (file_exists(dirname(__FILE__) . '/defines.php')) {
    include_once dirname(__FILE__) . '/defines.php';
}

if (!defined('_JDEFINES')) {
    define('JPATH_BASE', dirname(__FILE__));
    require_once JPATH_BASE.'/includes/defines.php';
}

require_once JPATH_BASE.'/includes/framework.php';
require_once JPATH_BASE.'/includes/helper.php';
require_once JPATH_BASE.'/includes/toolbar.php';

the problem is that you don't include Joomla framework and using JFactory. If any function contains error, you should include Joomla path for that function.
Restricted access problem solved with define('_JEXEC', 1);