Jc John Jc John - 1 year ago 91
JSON Question

codeigniter ajax getting the value of json from model

I am having trouble how to get the returned json from my controller to my view. The passing of the data is already okay, but i dont know how to decode or get the specific values of the json encoded.

All i want is to store my specific values of json to a variable for further use. Something like this :

$project_name = val.($json['project_name');

Here is my code from my view :

function showprojectdetails(projectSelected) {
var studentId = null;
url : "<?php echo site_url('manager/projects/ProjDetails/')?>/" + projectSelected,
type: "GET",
dataType: "JSON",
success: function(data) {

$json = json_decode(data, true);

error: function (jqXHR, textStatus, errorThrown) {
alert('Error get data from ajax');

my Controller :

function ProjDetails($project_title) {

$data = $this->project->getProjDetails($project_title);
echo json_encode($data);


My model :

function getProjDetails($project_title) {

$query = $this->db->query('SELECT * from project where project_code = "'.$project_title.'" ');

return $query->row();

Ish Ish
Answer Source

You dont need to decode the value in js. json_encode would convert array into json string. So what you get in view is already json. You simply needs to use it.

This will show you the json string in console.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download