我有一个我需要的类别和子类别表,当添加产品并且用户选择我选择的类别时,以下子类别列表应仅显示那些具有...的子类别...我在我的 admint.ctp 中使用 ajah一切似乎都很好,但我的控制器没有收到 ajah 请求
$('#category_id').change(function(){
$('.typecategories-select').fadeIn('slow');
var category_data = $(this).val()
console.log(category_data)
$.ajax({
type: "POST",
url: '<?php echo $this->Url->build(['controller' => 'Products', 'action' => 'add','plugin'=>'admin']); ?>',
data: {category_id:category_data},
success: function(data){
console.log('AjaX Success')
// console.log(data)
},
error: function(){alert('AjaX Failed')}
});
});
}
//ProductsController
public function add()
{
if ($this->request->is('post')){
$a = 'ajax success';
echo $a;
}
if ($this->request->is('put')){
$a = 'ajax success';
echo $a;
}
if ($this->request->is('ajax')) {
$a = 'ajax success';
echo $a;
}
else{
echo $value = $this->request->getData('category_id');
echo $value;
$a = 'a';
echo $a;
//here only return $a after i change #category_id but its ajax request wtf?
}
if ($this->request->is('json')){
$a = 'ajax success';
echo $a;
}
}