【发布时间】:2015-08-20 11:28:34
【问题描述】:
我在 ajax 发布时遇到问题。在下拉列表中选择父类别时,我尝试获取类别。但数据已发布。
我的业务主管
public function getcat($id)
{
echo "sdfad";
$cr=new Categoryrepo();
header('Content-Type: application/x-json; charset=utf-8');
echo(json_encode($cr->getcatbyparentid($id)));
}
我的类别模型
public function getcatbyparentid($id)
{
$this->db->select('id,name');
$this->db->from('category');
$this->db->where('parent',$id);
return $query=$this->db->get();
}
我的 ajax 代码
$(document).ready(function(){
$("#parent").change(function(){
var id=$('#parent').val();
alert(id);
$.ajax({
type:"POST",
url:"<?php echo base_url()?>business/getcat/"+id,
success: function(data)
{
alert(data);
}
});
});
});
请帮我解决一下
【问题讨论】:
-
好吧,在您的模型中,您没有从数据库返回任何结果。因此,您应该根据您的要求使用
result()或 Codeigniter documentation 的任何其他功能。而且,我真的没有得到你真正需要的东西。您是否在如何填充子下拉列表时遇到问题?还是因为返回的数据不正确?? -
结果如何,打印出来。你的问题不完整。同时向我们展示
console错误。
标签: php jquery ajax codeigniter