Table Structure cId category idcName category name gid parent level id this is my HTML page & amp; lt; selectname & quot; gType & quot; id & quot; gType & quot; & amp; gt; {code ...} ajax code & amp; lt; script & amp; gt ;$ (& #039; # gType & #039 ;). click (function () {code ...}}); & amp; lt; script & amp; gt; thinkph... table Structure
CId category id
CName category name
Gid parent id
This is my HTML page
{$ Val. cName}
Ajax code
Script
$ ('# Gtype'). click (function (){
$(this).change(function(){ var objectModel = {}; var value = $(this).val(); var type = $(this).attr('id'); objectModel[gType] =value; $.ajax({ cache:false, type:"POST", url:"/index.php/Goods/goodsAdd", dataType:"json", data:objectModel, timeout:30000, success:function(data){ $("#lables").empty(); var count = data.length; var i = 0; var b=""; for(i=0;i
"+data[i].cName+""; } $("#lables").append(b); } }); });
}
);
Script
Thinkphp receiving page
Public function goodsAdd (){
$model=M("category"); $rs=$model->where("pid=0")->select(); $this->assign("rs",$rs); $this->display(); $result = array(); $cate =$_POST['gType']; var_dump($cate); $result = M('category')->where(array('pid'=> $cate))->field('cId,cName')->select(); var_dump($result); $this->ajaxReturn($result,"JSON"); }
Where is the error? ajax is just getting started.
Reply content:
Table Structure
CId category id
CName category name
Gid parent id
This is my HTML page
{$ Val. cName}
Ajax code
Script
$ ('# Gtype'). click (function (){
$(this).change(function(){ var objectModel = {}; var value = $(this).val(); var type = $(this).attr('id'); objectModel[gType] =value; $.ajax({ cache:false, type:"POST", url:"/index.php/Goods/goodsAdd", dataType:"json", data:objectModel, timeout:30000, success:function(data){ $("#lables").empty(); var count = data.length; var i = 0; var b=""; for(i=0;i
"+data[i].cName+""; } $("#lables").append(b); } }); });
}
);
Script
Thinkphp receiving page
Public function goodsAdd (){
$model=M("category"); $rs=$model->where("pid=0")->select(); $this->assign("rs",$rs); $this->display(); $result = array(); $cate =$_POST['gType']; var_dump($cate); $result = M('category')->where(array('pid'=> $cate))->field('cId,cName')->select(); var_dump($result); $this->ajaxReturn($result,"JSON"); }
Where is the error? ajax is just getting started.
What is your normal PHP code segment? Why display and ajaxReturn ..