0
{"query":[{"uID":"U0016","name":"saman","nic":"911350521V","email":"saman@gmail.com","username":"saman","address":"colombo","telephone":"0342270443","type":"FREE"}],"field":["uID","name","nic","email","username","address","telephone","type"],"result":[{"uID":"U0014","name":"hafim","nic":"911350521V","email":"managerdulux@gmail.com","username":"fiham","password":"5dca0dc7c1fd78b5c90abbb0db69aed7","address":"colombo","telephone":"0342270443","type":"ADMIN"},{"uID":"U0018","name":"fast","nic":"911350521V","email":"pasdulanjaya@gmail.com","username":"fast","password":"31d4541b8e926a24f0c9b835b68cfdf3","address":"colombo","telephone":"0342270443","type":"ADMIN"},{"uID":"U0019","name":"hafima","nic":"911350521V","email":"fihamzuher@gmail.com","username":"hafim","password":"8f49a4ca3aeffd575ba8c25276ff061f","address":"colombo","telephone":"0342270443","type":"ADMIN"}],"userid":[{"uID":"U0013"},{"uID":"U0016"},{"uID":"U0020"},{"uID":"U0021"},{"uID":"U0024"},{"uID":"U0025"}],"adminid":[{"uID":"U0014"},{"uID":"U0018"},{"uID":"U0019"}],"updatefield":["name","nic","address","telephone"]}

这是我的 json 对象,我需要将“查询”数据获取到我的表中如何执行此操作

这是我的ajax调用

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
            <script> function makesearchCall(){ 
        $.ajax({
             type: "post",
             url: "<?php echo site_url(); ?>/controller_d/login/admin_search_user",
             cache: false,               
             data: $('#docContainer1').serialize(),
             success: function(json){   
             try{   
             var obj = jQuery.parseJSON(json);




              }catch(e) {
                    alert('Exception while request..');
                     }  }, 
                     error: function(){
                            alert('Error while request..'); 
                            } }); } 
                            </script> 
4

1 回答 1

0

循环obj.query并使用.运算符获取值

尝试这个

 $.ajax({
     type: "post",
     url: "<?php echo site_url(); ?>/controller_d/login/admin_search_user",
     cache: false,               
     data: $('#docContainer1').serialize(),
     dataType:"JSON",  //<----here
     success: function(json){   
          var str= "<table><tr>";
         $.each(json.query,function(i,v){
           alert(v.uID); //gives U0016
           alert(v.name); //gives saman
           str+="<td>"+v.uID+"</td>";
           str+="<td>"+v.name+"</td>";
        })
        str+="</tr></table">;
        $("body").append(str);
 } 
于 2013-09-09T05:12:17.277 回答