【发布时间】:2015-05-08 17:11:22
【问题描述】:
我正在使用 Magento 1.9,在页面 .phtml 中我有一个 AJAX 请求:
$('#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');
}
});
}
});
myfile.php 的内容是:
<?php
$id = $_POST['id'];
echo $id;
?>
工作效果很好,$ ID在.classe @时,选择表单的值> 0,但我希望在myfile.php中有父类别的子类别,具有id = $ id
我尝试添加此代码:
$children = Mage::getModel('catalog/category')->getCategories($id);
foreach ($children as $subcategory) {
echo $subcategory->getName();
}
该代码在 .phtml 中有效,但如果我将其添加到 myfile.php 中,我将一无所获。
有什么想法吗?
【问题讨论】:
标签: php jquery ajax magento magento-1.9