{"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>
答案 0 :(得分: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);
}