insert tr html code into tbody programmatically.not display tr layout

Tags: , ,



i want to get tr html tbody display data but not sow . i am sharing all code usnig Codeigniter and javascript please share valuable idea..

view (HTML)

<input type="button" onclick="last_reports()" value="Last Reports" class="btn btn-reports btn-sm" data-toggle="modal" data-target="#last-reports">

tbody Modal

javascript

<script>
  
    function last_reports()
    {
       var aptid        =   $("#get_patientid").val(); 
       
        $.ajax({
        url: "<?php echo base_url(); ?>test-lab-history",
        type: "post",
        data: "apid="+aptid,
        success: function (response)
            {
            var res = JSON.parse(response); 
             console.log(res);
             
            var j=1;            
                for(i=0;i<res.length;i++)
                        {
                           
                            val+='<tr>';
                            val+='<td>'+ j++ +'</td>';
                            val+='<td>'+res[i]['tests']+'</td>';
                            val+='<td>'+res[i]['comp_name']+'</td>';
                            val+='<td>'+res[i]['remark']+'</td>';
                            val+='<td>'+res[i]['report_name']+'</td>';
                            val+='<td><a class="btn btn-primary btn-sm" href="'+res[i]['report_pic_url']+'" download><i class="fa fa-download" aria-hidden="true"></i></a></td>';
                            val+='<td><input type="checkbox" name="id[]" value="'+res[i]['id']+'"></td>';
                            val+='</tr>';

                            $('#tables').html(val); 
                        }
            }
        });
    }


    </script>

Answer

Your question is confusing, but I think, you need to transfer $('#tables').html(val) outside the for loop.



Source: stackoverflow