簡體   English   中英

單擊按鈕時,在另一個數據表中顯示選中的行

[英]Display the checked row in another datatable when the button is clicked

在另一個表中顯示選中的行值首先,我試圖通過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>

我正在ajax中發送多個ID。 我的模特是

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();
}

在我的控制台中,我得到的輸出為:

Array
(
[0] => stdClass Object
    (
        [echo_id] => 1
        [echo_scan] => Echo

        [price] => 1000
    )

[1] => stdClass Object
    (
        [echo_id] => 2
        [echo_scan] => Fetal Echo
        [price] => 1500
    )

  )

但是我不知道如何在數據表中追加...否則我必須使用JavaScript在數據表中顯示選中的行....我是Ajax的新手,所以請建議我

從模型而不是數組返回Json

return json_encode($query->result());

得到回應后顯示您的數據

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM