如何从AJAX返回值?

I'm new to ajax and json. Hope to have some helps here!

my.php:

jQuery(".btn").click(function() {

            var catid = jQuery(this).attr('id');
            jQuery.ajax({
                type: "POST",
                url: '../ajax.php',
                data: "catid=" + catid,
                success: function(data)
                {
                    alert("success!");
                }
            });
        });

ajax.php:

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__) );

require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );

$catid = $_POST['catid'];

$db = JFactory::getDBO();
$user = JFactory::getUser();

if (isset($catid)){

    $sql = 'SELECT a,b,c,d';
    $sql .= ' FROM `#__table1` 1 INNER JOIN `#__table2` 2 ON 1.id = 2.id';
    $sql .= ' WHERE title COLLATE UTF8_GENERAL_CI like "%'.$catid.'%"';
    $db->setQuery($sql);
    $db->query();
    $num_rows = $db->getNumRows();
    $result = $db->loadRowList();

}

i need to return the $num_rows and the $result (columns a,b,c,d) to my.php to proceed. How can I do that? must json return value from array?

Thank you!