js循环处理后台返回的json数组

时间:2022-01-14 22:17:48
js循环处理后台返回的json数组
 <script type="text/javascript">
     function gongdan_search(elm){
         var dangqian_value=$(elm).val();
         if(dangqian_value){
             $.ajax({
             url:'__URL__/order_infos_list_search',
                 type:'post',
                 data:{dangqian_value:dangqian_value},
                 success:function(data){
                     ){
                         var d=eval("("+data+")");//js循环处理后台返回的json数组
                         var company=d.company;
                         var cus_name=d.cus_name;
                         var addr=d.addr;
                         var cus_mobi=d.cus_mobi;
                         var wnumber=d.wnumber;
                         if(company){
                             $('.company_view').html(company);
                         }
                         if(cus_name){
                             $('.cus_name_view').html(cus_name);
                         }
                         if(addr){
                             $('.addr_view').html(addr);
                         }
                         if(cus_mobi){
                             $('.cus_mobi_view').html(cus_mobi);
                         }
                         if(wnumber){
                             $('.gongdanhao_view').val(wnumber);
                         }
                     }else{
                         $('.company_view').html('暂无数据');
                         $('.cus_name_view').html('暂无数据');
                         $('.addr_view').html('暂无数据');
                         $('.cus_mobi_view').html('暂无数据');
                     }
                 }
             });
         }
     }
 </script>

     public function order_infos_list_search(){
         $dangqian_value=$this->_post('dangqian_value');
         if(!$dangqian_value){
             return false;
         }
         $where=null;
         $where['wnumber']=$dangqian_value;
         $result=M('order_list')->where($where)->field('wnumber,uid,cus_name,cus_mobi,addr')->find();
         if(!$result['uid']){
             return false;
         }
         $map=null;
         $map['uid']=$result['uid'];
         $factory_infos=M('user_factory')->where($map)->field('company')->find();
         if(!$factory_infos){
             return false;
         }
         $arr=array();
         $arr['company']=$factory_infos['company'];
         $arr['cus_name']=$result['cus_name'];
         $arr['addr']=$result['addr'];
         $arr['cus_mobi']=$result['cus_mobi'];
         $arr['wnumber']=$result['wnumber'];
         if(!empty($arr)){
             echo json_encode($arr);  //返回josn数组
         }else{
             echo ;
         }
     }

 var content1=$("input[name='compliant_jibie']:checked").val();  //jquery选中当前radio按钮获取值
 alert(content1);