使用带有代码点火器的Ajax,使用po_id和item_id更新quantity_received详细信息时出现问题。我的问题是,当我更新po_id = 5和item_id = 1时,quantity_received详细信息会更新。再次当我更新第二项po_id = 5和item_id = 2时,quantity_received细节没有得到更新,同样的值已经更新,我在item_id = 1 ..
My code:
<table class="table table-striped table-hover table-bordered mytable order-table" id="table">
<thead>
<tr>
<th>PO Id</th>
<th style="width:0px;">Item Id</th>
<th>Item Name</th>
<th>Quantity</th>
<th>Add RO</th>
<th colspan="2">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($pitems as $result)
{
?>
<tr class="">
<td><input type="text" disabled name="po_id" id="po_id" value="<?php echo $result->po_id; ?>"/></td>
<td><input type="text" disabled name="item_id" id="item_id" value="<?php echo $result->item_id; ?>"/></td>
<td><input type="text" disabled name="item_name" id="item_name" value="<?php echo $result->item_name; ?>"/></td>
<td><input type="text" disabled name="quantity_purchased" id="quantity_purchased" value="<?php echo $result->quantity_purchased; ?>"/></td>
<td><input type="text" name="quantity_received" id="quantity_received" required placeholder="Enter Received Items" value="<?php echo $result->quantity_received; ?>"/></td>
<!--td><span class="action"><a href="#" id="<?php echo $result->po_id.'/'.$result->item_id; ?>" class="delete" title="Delete">X</a></span></td-->
<td><span class="action"><a href="#" id="<?php echo $result->po_id.'/'.$result->item_id.'/'.$result->quantity_purchased.'/'.$_POST['quantity_received']; ?>" class="edit" title="Edit">Add</a></span></td>
<?php
}
?>
</tbody>
</table>
的Ajax:
$(".edit").click(function(){
var element = $(this);
var del_id = element.attr("id");
var arr = del_id.split('/');
var quantity_purchased = $('#quantity_purchased').val();
var quantity_received = $('#quantity_received').val();
var del_id1 = element.attr("id");
if(confirm("Are you sure you want to Edit this?"))
{
$.ajax({
type: "POST",
url: "<?php echo base_url().'/inventory_c/ro_edit_poid11' ?>",
cache: false,
data: 'po_id='+arr[0]+'&item_id='+arr[1]+'&quantity_received='+quantity_received,
dataType: "html",
success: function(htmldata) {
alert("success");
}
});
}
return false;
});
我的控制器很有趣:
public function ro_edit_poid11()
{
$po_id = $_POST['po_id'];
$item_number = $_POST['item_id'];
$quantity_received = $_POST['quantity_received'];
$last_id= $po_id;
$edit_temp_purchase = array(
'quantity_received' => $quantity_received,
);
$this->db->where(array('po_id' => $po_id, 'item_id' => $item_number));
$this->db->update('bgs_po_list_items', $edit_temp_purchase);
[enter image description here][1]
}
请做我的需要@谢谢
答案 0 :(得分:1)
为以下2个输入框提供不同的ID
$(document).on('click','a.edit',function(){
var element = $(this);
var del_id = element.prop("id");
var arr = del_id.split('/');
var po_id = parseInt(arr[0]);
var item_id = parseInt(arr[1]);
var quantity_purchased = $('#quantity_purchased_'+po_id+'_'+item_id).val();
var quantity_received = $('#quantity_received_'+po_id+'_'+item_id).val();
var del_id1 = element.attr("id");
if(confirm("Are you sure you want to Edit this?"))
{
$.ajax({
type: "POST",
url: "<?php echo base_url().'/test/ro_edit_poid11' ?>",
cache: false,
data: 'po_id='+arr[0]+'&item_id='+arr[1]+'&quantity_received='+quantity_received,
dataType: "html",
success: function(htmldata) {
alert("success");
}
});
}
});
然后获取数量购买的价值并在您的jquery中获得如下:
public function ro_edit_poid11()
{
$po_id = $_POST['po_id'];
$item_number = $_POST['item_id'];
$quantity_received = $_POST['quantity_received'];
$last_id= $po_id;
$edit_temp_purchase = array(
'quantity_received' => $quantity_received,
);
$this->db->update('bgs_po_list_items',$edit_temp_purchase,['po_id' => $po_id, 'item_id' => $item_number]);
echo 'success';
}
在php函数中返回ajax的回显
custom doclet
希望这会奏效。