在Codeigniter中单击“编辑”按钮时更新引导表

时间:2017-05-31 05:14:32

标签: javascript php jquery twitter-bootstrap codeigniter

下面。我有codeigniter更新代码,它也工作,但问题是当我单击编辑按钮没有解析空格数据后。 (在更新模型中没有获取空格词之后)。 我该如何解决这个问题。

vvIncome.php视图

$(document).on('click','.btn_edit', function(e) {
  $("#edit").val($(this).attr('edit_id'));
  $("#in_dis").val($(this).attr("in_dis"));
  $("#in_amnt").val($(this).attr('in_amnt'));
  $("#confirm-edit").modal({show:'true'});
	   		
});
			
$(document).on('click', '#btn-ys', function() {  	
var income_id = $('#edit').val();
var in_dis = $('#in_dis').val();  
var in_amnt = $('#in_amnt').val();
var result{"income_id":income_id,"in_dis":in_dis,"in_amnt":in_amnt};
	   			
 $.ajax({
data:result,
type: "POST",
url:'<?php echo base_url(); ?>admin/income/editincome/'+income_id,
success: function(data){    
$("#confirm-edit").modal('hide');
viewData();
	  	 }
	});
});

查看PHP代码

<div class="modal fade bs-example-modal-md" id="confirm-edit" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
 <div class="modal-dialog modal-md" role="document">
 <div class="modal-content">
<div class="modal-header">
 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">EDIT CATEGORY</h4>
</div>

<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="well">
<form class="form-horizontal">

<div class="form-group">
 <div class="col-md-12">
 <input type="text"class="form-control" id="in_dis" placeholder="description">
</div>
 </div>

<div class="form-group">
<div class="col-md-12">
 <input type="number" class="form-control" id="in_amnt" placeholder="amount">
 </div>
  </div>

 <div class="form-group">
 <div class="col-md-12">
 <input type="hidden" class="form-control"     id="edit" placeholder="income_id">
</div>
 </div>

 <div class="modal-footer">
 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
 <button type="button" id="btn-ys" class="btn btn-success">SUBMIT</button>
 </div>
 </form>
    </div>
</div>         
    </div>
 </div>

` 的 Income_resut.php

<thead>
<tr>
<th ><center>DESCRIPTION</center></th>
<th ><center>AMOUNT</center></th>
<th ><center>EDIT</center></th>
<th ><center>DELETE</center></th>
</tr>
</thead>
<?php foreach ($incm as $in_key) { ?>
	<tr>
<td><center><?php echo $in_key->description;?></center></td>
<td><center><?php echo $in_key->amount;?></center></td>
<td>
<center><button type="button" title="edit" data-toggle="modal" edit_id=<?php echo $in_key->income_id;?> in_dis=<?php echo $in_key->description;?> in_amnt=<?php echo $in_key->amount;?>  class="btn btn-info btn_edit"><i class="fa fa-pencil"></i></button></center>
</td>
<td>
<center><button type="button" title="delete" data-toggle="modal" del_id=<?php echo $in_key->income_id;?> class="btn btn-danger btn-delete"><i class="fa fa-trash-o"></i></button></center>
</td>
<?php } ?>
 </table>

`

income.php控制器

public function editincome($income_id)
{
$udata['income_id'] = $this->input->POST('income_id'); 
$udata['description'] = $this->input->POST('in_dis');
$udata['amount'] = $this->input->POST('in_amnt');
$update = $this->income_model>update_income_details($udata,$income_id);
 }

Income_Model.php 型号

public function update_income_details($udata,$income_id)
 {
 $this->db->from('income', $udata);
 $this->db->where('income_id',$income_id );
 return $this->db->update('income',$udata);
 }

此视图表 enter image description here

这是编辑模型 enter image description here

1 个答案:

答案 0 :(得分:0)

尝试更改为此,

例如,in_dis=<?php echo $in_key->description;?>data-in_dis="<?php echo rawurlencode($in_key->description); ?>"

然后 $("#in_dis").val($(this).attr("in_dis"));$("#in_dis").val(decodeURIComponent($(this).data("in_dis")));

使用.data()代替.attr()

让我知道它是否适合你。