[英]How to remove html code from json response
I'm trying to call get_child method through ajax in my form textbox change event. 我正在尝试通过表单文本框更改事件中的ajax调用get_child方法。 I want to show results in datalist. 我想在数据列表中显示结果。 below is the code i have used. 以下是我使用的代码。
$sql = "SELECT * FROM tbl_child Where `id_mother`=?";
$results = $db->load_result($sql,array('M-00000001'));
$child = array();
foreach($results as $row){
$child[]=$row;
}
echo json_encode($child,JSON_PRETTY_PRINT);
die;
my script is: 我的脚本是:
$('#mother_name').on('keyup', function(e){
//e.preventDefault();
$.ajax({
url:"<?php echo $this->to_url('get-child'); ?>",
type:"GET",
datatype : "json",
contentType: "application/json; charset=utf-8",
success: function(data, status){
console.log(data);
//$(data).each(function() {
// names = "<option value=\"" + this.id_child + "\">" + this.child_name + "</option>";
// $('#childname').append(names);
//});
},
error: function(xhr, desc, err){
console.log(xhr);
}
});
});
but when i calling, following output is displayed. 但是当我打电话时,显示以下输出。 it contain html tags with results. 它包含带有结果的html标记。 when i select particular data from the result it said 'undefined' how can i solve this problem pls help me. 当我从结果中选择特定数据时,它说“未定义”,我该如何解决此问题,请帮我。 i'm new to json. 我是json的新手。
[
{
"id_child": "0000000001",
"id_mother": "M-00000001",
"child_name": "marli",
"child_lname": "",
"dob": "2015-05-09 00:00:00",
"gender": "1",
"birth_weight": "3100.00",
"birth_height": "55.00",
"head_Perimeter": "34.00",
"reg_by": "O-00000001",
"created_date": "2016-05-12 21:40:25",
"10": "2016-05-12 21:40:25"
}]
thank you guys 感谢大伙们
[
{
"id_child": "0000000001",
"id_mother": "M-00000001",
"child_name": "marli",
"2": "Kathirvelan",
"child_lname": "",
"dob": "2015-05-09 00:00:00",
"gender": "1",
"birth_weight": "3100.00",
"birth_height": "55.00",
"head_Perimeter": "34.00",
"reg_by": "O-00000001",
"created_date": "2016-05-12 21:40:25",
"10": "2016-05-12 21:40:25"
}]
From my understanding there are no html in here rather it is a array of elements . 据我了解,这里没有html,而是一个元素数组。
data = [
{
"id_child": "0000000001",
"id_mother": "M-00000001",
"child_name": "marli",
"child_lname": "",
"dob": "2015-05-09 00:00:00",
"gender": "1",
"birth_weight": "3100.00",
"birth_height": "55.00",
"head_Perimeter": "34.00",
"reg_by": "O-00000001",
"created_date": "2016-05-12 21:40:25",
"10": "2016-05-12 21:40:25"
}]
Where is the html tag in the above output? and if you want to read any object value
console.log(data[0].id_child);
because its an array object, you have to put index to read the value.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.