Custom Ajax file in Joomla

<?php
    define('_JEXEC', 1);
    define('JPATH_BASE', realpath(dirname(__FILE__) . '/../../'));  
    require_once JPATH_BASE . '/includes/defines.php';
    require_once JPATH_BASE . '/includes/framework.php';

    $mainframe = JFactory::getApplication('site');
$db = JFactory::getDBO();
 $query = "SELECT distinct `customfield_value` FROM `jos_virtuemart_product_customfields` WHERE `virtuemart_custom_id` = '17'";
 //echo $query;
 $db->setQuery($query);
 $result = $db->loadObjectList();
 
 echo '<pre>';
 print_r($result);
 echo '</pre>';
?>
Joomla, PHP