-2
我试图从数据库中获取数据并使用php中的jquery绑定到html表格。结果正确显示。但我想要将数据提取到文本框内,这意味着提取的数据应该是可编辑的。请按我的需求。从数据库中获取数据并绑定到使用php中的jquery的html表格
我的代码是。
$.ajax({
type: "POST",
url: "add_temp_purchase",
cache: false,
data: 'itemnum='+itemnum+'&quantity='+quantity+'&customer_id='+customer_id,
dataType: "html",
success: function(returnhtml) {
//alert(customer_id);
$.ajax({
type: "GET",
url: "gettempid",
cache: false,
data: 'customer_id='+customer_id,
dataType: "html",
beforeSend: function() {
$('#metable').html('loading please wait...');
},
success: function(htmldata) {
var order_id = order_id;
var customer_id = customer_id;
var item_id = itemnum;
var count = quantity;
alert(customer_id);
$(".metable").find('tbody').append('<tr><td>' + order_id +
'</td><td><input type="text">' + customer_id +
'</td><td><input type="text">' + item_id +
'</td><td><input type="text">' + count +
'</td></tr>');
}
});
我的HTML代码是:
<table class="table table-striped table-hover metable table-bordered" id="editable-sample">
<thead>
<tr>
<th>Id</th>
<th>Customer Id</th>
<th>Item Number</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
foreach ($tempresults as $result)
{
?>
<tr class="">
<td><input type="text" name="order_id" id="order_id" value="<?php echo $result->order_id;?>"></td>
<td><input type="text" name="customer_id" id="customer_id" value="<?php echo $result->customer_id;?>"></td>
<td><input type="text" name="item_id" id="item_id" value="<?php echo $result->item_id;?>"></td>
<td><input type="text" name="count" id="count" value="<?php echo $result->count;?>"></td>
</tr>
<?php
}
?>
</tbody>
</table>
Thanks,
在你的AJAX的返回的数据,通过做'$(“#ORDER_ID”)设置每个文本字段的值VAL(result.correspondingdata);'(假设您在返回的数据数组)。 –