我正在編寫一個應用程序,它基於id
給出的基礎上從數據庫中提取數據並返回表中的行,它是一個條形碼計費模塊,它.append
該行作爲條形碼字符串給出,但我面臨的問題,當我正在返回表row as a HTML
代碼<tr>..</tr>
,通過ajax
我看不到新表格行打印(添加)在我的表上。將表格行作爲HTML代碼通過ajax添加到表格中
這是我的觀點:
<table class="table table-bordered">
<thead>
<tr>
<th>S No.</th>
<th>Particular</th>
<th>QTY</th>
<th>Cost</th>
<th>Discount</th>
<th>Discard</th>
</tr>
</thead>
<tbody class="todo_list">
<?php echo $list;?>
<input type="hidden" name="bill_ref" value="<?php echo $bill_ref ?>"/>
<input type="hidden" name="date" value="<?php echo $date ?>"/>
</tbody>
<?php echo $total_bill; ?>
<div id="bill_tbl">
<--!MY NEW ROW SUPPOSED TO BE ADDED HERE!-->
</div>
</table>
我的AJAX JS:
<script type="text/javascript">
$(document).ready(function(){
$("#c_id").change(function(){
var send_data=$("#c_id").val();
$.ajax({
type:"post",
url:"billing_table",
dataType: "html",
data:"i_id_post="+send_data,
success:function(data){
$("#bill_tbl")..after(data);
}
});
});
});
</script>
和我的控制器(用於測試目的,我正在操作我的控制器DB一部分我很抱歉這一點):
public function billing_table()
{
$b_barcodestring=$this->input->post('b_barcodestring');
$i_id=$this->input->post('i_id_post');
if($i_id==''&& $b_barcodestring!='')
{
echo $b_barcodestring;
}
else if($b_barcodestring=='' && $i_id!='')
{
//i want to print sumple this dummy row in my table
echo '<tr ><input type="hidden" name="counter[]" value="ssss"></tr><tr ><td>+counter+</td> <input type="hidden" name="particular[]" value="Greting Card" ><td>'.$i_id.'</td> <td> <input type="number" name="qty[]" value="+qty_cal+"></td> <td> <input type="hidden" name="cost[]" value="150" >150</td> <td><input type="hidden" name="discount[]" value="N/A">N/A</input></td> <td ><button class="btn btn-danger"><i class="icon-remove icon-white"></i>Delete</button></td></tr>';
}
$this->output->enable_profiler(TRUE);
}
這裏是FIDDLE。
,而不是$(」 #bill_tbl「).. after(data)try $(」#bill_tbl「)。after(data) –
@VinodLouis:ya我嘗試了額外的」。「是我的打字錯誤,它仍然不起作用 – user2652367
我不認爲你可以在tbody或thead之外的表格中添加一行,我的意思是我認爲它不會是w3c c沒有依從,但不確定它是否是問題的根源。你應該真的考慮檢查你的輸出佈局imho。 – nubinub