[英]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. 我不是很喜欢jquery,这就是为什么我越来越难以获得结果。 I want to get the specific result of the ajax.
我想得到ajax的具体结果。 The result of the ajax is like this:
ajax的结果如下:
{"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
? 我如何只获得
cal_events_image
的值? Take note there are multiple result. 请注意,有多个结果。 Should I use
.each
function for that? 我应该使用
.each
函数吗? Thank you guys in advance. 预先谢谢你们。
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"]);
You need to parse it using json. 您需要使用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. 然后它将根据其值显示结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.