我创建了一个编辑表单,我只想更新资产表单字段。在这里,我使用jQuery的keyup函数,通过它我想要更新我的资产表单字段值而不刷新页面和按钮。但是现在只有单行值已经更新,我有多行。它总是更新第一行数据。那么,我该如何解决这个问题呢?请帮帮我。
controller:test.php
public function update_assets()
{
$data = array(
'assets_id'=> $this->input->post('assets'),
);
$where = "admin_id = '".$this->input->post('admin_id')."' and inventory_id = '".$this->input->post('inventory_id')."'";
$this->db->where($where);
$this->db->update('inventory',$data);
echo $this->db->last_query();
}
观点:
<script>
$(document).ready(function(){
$(".assets").keyup(function(){
inventory_id = $("#inventory_id").val();
assets = $("#assets"+inventory_id).val();
admin_id = $("#admin_id").val();
$.ajax({
type:"POST",
data:{"assets":assets, "admin_id":admin_id, "inventory_id":inventory_id},
url:"<?php echo base_url('index.php'); ?>/test/update_assets",
success:function(data){
alert(data);
}
});
});
});
</script>
<input type="hidden" name="admin_id" id="admin_id" value="<?php echo $logg; ?>">
<input type="hidden" name="inventory_id" id="inventory_id" value="<?php echo $inventory_id; ?>">
<input type="text" name="assets" id="assets<?php echo $inventory_id; ?>" />
谢谢