Magento Ajax和Mage :: getModel

I'm using Magento 1.9 and in a page .phtml I have an AJAX request:

$('#dive').change(function() {
    if($(this).val() > 0) {
        $j.ajax({
            url: 'dominio.com/myfile.php',
            type: 'POST',
            data: { id: $(this).val() },
            success: function(data) {
                $('.classe').html(data);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert('error');
            }    
        });
    }
});

The content of myfile.php is:

<?php 
     $id = $_POST['id'];
     echo $id;
?>

It works well the $id is shown in .classe when the value of select form is > 0 but I want to have inside of myfile.php the subcategory of parent category with id = $id

I tried to add this code:

$children = Mage::getModel('catalog/category')->getCategories($id);
foreach ($children as $subcategory) {
    echo $subcategory->getName();
}

That code works in .phtml but if I add that in myfile.php I get nothing.

Any ideas?

You probably miss application initialization. if this is your entire php code:

<?php 
     $children = Mage::getModel('catalog/category')->getCategories($id);

foreach ($children as $subcategory) {
      echo $subcategory->getName();
}
?>

you need to add Mage.php and start Mage::app();

<?php 
require_once ('app/Mage.php');
Mage::app();
$children = Mage::getModel('catalog/category')->getCategories($id);

foreach ($children as $subcategory) {
      echo $subcategory->getName();
}
?>

it looks like you probably don't use new controller so you need to initialize the app again.