我想通過ajax在我的表單文本框更改事件中調用get_child方法。我想在datalist中顯示結果。下面是我使用的代碼。如何從json響應中刪除html代碼
$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;
我的腳本是:
$('#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);
}
});
});
但是當我打電話時,會顯示以下輸出。它包含帶結果的html標籤。當我從結果中選擇特定的數據時,它說'未定義'我該如何解決這個問題,請幫助我。我是json的新手。
- 菜單
- 菜單2
[
{
"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"
}]
感謝你們
我不清楚你在問什麼。 –
顯示帶有html標籤的json的示例 –
如何從json響應中獲取特定值。問題是我的jQuery返回數組結果的頭信息,並且響應類型是String。 – Dilee