[英]Display the checked row in another datatable when the button is clicked
Display the checked row values in another table Firstly im trying to display the records in another table through Ajax.. 在另一个表中显示选中的行值首先,我试图通过Ajax在另一个表中显示记录。
<script>
$(document).ready(function() {
$('#btn').click(function() {
var dataArr = [];
$('input:checked').each(function() {
alert($(this).closest('tr[id]').attr('id'));
dataArr.push($(this).closest('tr[id]').attr('id'));
});
// send data to back-end via ajax
$.ajax({
type : "POST",
url : 'Server.php/user',
data : "content="+dataArr,
success: function(data) {
alert(data);// alert the data from the server
},
error : function() {
}
});
});
});
</script>
I am sending multiple id in ajax. 我正在ajax中发送多个ID。 My model is
我的模特是
function get_row_details($jsonvalue) {
$this->db->select("echo_id,echo_scan,price");
$this->db->from('echo_investigation');
$this->db->where_in('echo_id', $jsonvalue);
$query = $this->db->get();
return $query->result();
}
In my Console I am getting the output as: 在我的控制台中,我得到的输出为:
Array
(
[0] => stdClass Object
(
[echo_id] => 1
[echo_scan] => Echo
[price] => 1000
)
[1] => stdClass Object
(
[echo_id] => 2
[echo_scan] => Fetal Echo
[price] => 1500
)
)
But I don't know how to append in data table...Or else i have to use JavaScript to display the checked row in datatable....I am new to Ajax so Kindly Suggest me 但是我不知道如何在数据表中追加...否则我必须使用JavaScript在数据表中显示选中的行....我是Ajax的新手,所以请建议我
Return Json From Model Instead Of Array 从模型而不是数组返回Json
return json_encode($query->result());
after getting response show your data 得到回应后显示您的数据
success: function(data) {
var obj = JSON.parse(data);
for (var i = 0; i < obj.length; i++){
console.log("Echo_ID : "+obj[i].echo_id);
console.log("Echo Scan: "+obj[i].echo_scan);
console.log("Price: "+obj[i].price);
//do your stuff here
}
});
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.