I've received data fro Json as below But I don't understand much about Json object and Json array. I've always confused with it. another hand I would like to ask expert here. How can I passing data from this json data to any div after ajax respond
Issue can't passing data to html element from this json
Here is my json data
{
"res": {
"nav": [
{"text":"SERVICES"},
{"text":"CooSurf"},
{"text":"CooMartsdf"},
{"text":"Devices"},
{"text":"asdf"},
{"text":"Press Release"},
{"text":"Speach"},
{"text":"fqas"},
{"text":"Network Coverages"},
{"text":"CooSurf"},
{"text":"CooMartsdf"},
{"text":"Devices"},
{"text":"test"}
],
"content": [
{"name":"Englishasdfasdf"},
{"name":"kh_nameasdfasdf"},
{"name":"asdfasdfasdf"},
{"name":"sdfasdfasdf"},
{"name":"English"},
{"name":"English"},
{"name":"FQAS"},
{"name":"Network Coverages"},
{"name":"kh_nameasdfasdf"}
],
"promot": [
{"title":"Englishasffasdf"},
{"title":"kh_namedfasdfasdf"},
{"title":"English"},
{"title":"English"},
{"title":"English"},
{"title":"asdfasdfas"},
{"title":"asdfasdfasdf"},
{"title":"asdfasdfasd"}
]
}
}
Here is my ajax
$.ajax({
type: method,
url: url,
data: $("#searching_from").serialize(),
dataType: "json",
cache: false,
beforeSend: function () {
$('#myModal').modal('show');
$(".loadings").css({'display': 'inline'});
}, success: function (data) {
var json = data.res;
var obj = JSON.parse(json);
console.log(obj );
$(".modal-body").append(data.res);
$(".loadings").css({'display': 'none'});
}
});
** This is function in Model **
public function search_data($keyword) {
if ($this->msearch($keyword, 'text', 'nav') == TRUE) {
$res['nav'] = $this->gsearch($keyword, 'text', 'text', 'nav');
}if ($this->msearch($keyword, 'name', 'content') == TRUE) {
$res['content'] = $this->gsearch($keyword, 'name', 'name', 'content');
}
if ($this->msearch($keyword, 'title', 'promot') == TRUE) {
$res['promot'] = $this->gsearch($keyword, 'title', 'title', 'promot');
} else {
$res[] = false;
}
return json_encode(array('res' => $res));
}
public function msearch($keyword, $like_col, $table) {
$this->db->like($like_col, $keyword);
$query = $this->db->get($table);
if ($query->num_rows() > 0) {
return TRUE;
} else {
return false;
}
}
public function gsearch($keyword, $like_col, $select, $table) {
$this->db->select($select);
$this->db->like($like_col, $keyword);
$query = $this->db->get($table);
return $query->result();
}