angel1108
angel1108

Reputation: 333

How to get specific ajax result in codeigniter

I am not really into jquery that's why I am getting hard to get the result. I want to get the specific result of the ajax. The result of the ajax is like this:

{"success":1,"result":[{"id":"7","cal_events_name":"Day Off","cal_events_image":"\/assets\/img\/3_copy_copy1.png"}]}
{"success":1,"result":[{"id":"8","cal_events_name":"Normal Day","cal_events_image":"\/assets\/img\/2_copy1.png"}]}

How can i get only the value of cal_events_image ? Take note there are multiple result. Should I use .each function for that? Thank you guys in advance.

Upvotes: 0

Views: 66

Answers (2)

curiosity
curiosity

Reputation: 844

You need to parse it using json. something like this...

success: function(response) {
var jsonData = JSON.parse(response);
   for (var i = 0; i < jsonData.result.length; i++) {
     var counter = jsonData.result[i];
     console.log(counter.cal_events_image);
   }
}

Then it will display the result according to it's value.

here is the working example: js Fiddle

Upvotes: 1

Manikiran
Manikiran

Reputation: 1

You can try this:

let response={"success":1,"result":[{"id":"7","cal_events_name":"Day Off","cal_events_image":"\/assets\/img\/3_copy_copy1.png"}]};
//response=JSON.parse(response);  // Use this line, if the response you get is in string format
alert(response["result"][0]["cal_events_name"]);

Upvotes: 1

Related Questions