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?