我已设置模态警报以更改状态,但仅在打开模态警报时状态会自动更改。我只需要点击模态的ok
按钮就可以改变状态,任何人都可以帮助我吗?
我的控制器
public function Changetobilledstatus()
{
$id=$this->input->post('value');
$data=array('Rental_status'=>3);
$this->General_model->update($this->table,$data,'RA_id',$id);
echo json_encode($data);
}
我的HTML
<div id="UnbilledModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Do You Need update status into billed ?</h4></div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary option">OK</button>
</div>
</div>
</div>
</div>
我的剧本
$('td', row).eq(10).html('<center><select id="Rental_status" onchange="changeStatus('+data['RA_id']+')"><option value="1">Select</option><option value="2">Billed</option></select></center>');
function changeStatus(RA_id){
var val=$("#Rental_status").val();
var id= RA_id;
if(RA_id){
$.ajax({
url:"<?php echo base_url()?>index.php/Rental_agreement/Changetobilledstatus",
type: 'POST',
data: {value:RA_id},
dataType: 'json',
success:
function(data)//quotation_status
{
//location.reload();
//alert(data['quantity']);
$('#UnbilledModal').modal();
},
error:function(e){
console.log("error");
}
});
}
}
=>您的HTML代码
$('td', row).eq(10).html('<center><select id="Rental_status" onchange="changeStatus('+data['RA_id']+')"><option value="1">Select</option><option value="2">Billed</option></select></center>');
//在选择中你必须以这种方式编写代码
'<a title="Change Status" class="btn btn-danger btn-xs" data-user="' + id + '" data-status="' + data + '" href="#UnbilledModal" data-toggle="modal" onclick="change_status(this)">Disable</a>'
<div id="UnbilledModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<?php echo form_open('your url', array('class' => 'form-horizontal', 'name' => 'your form name')); ?>
<input type="hidden" name="id" /> //fetch id and status
<input type="hidden" name="status" />
<h4 class="modal-title">Do You Need update status into billed ?</h4></div>
<div class="pull-right">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="submit" class="btn btn-success">Yes</button>
</div>
<?php echo form_close(); ?>
<div class="modal-footer">
<button type="submit" class="btn btn-primary option">OK</button>
</div>
</div>
</div>
</div>
=>您的Javascript代码
function change_status(obj) {
var id = $(obj).data('id');
var status = $(obj).data('status'); // here you can fetch data value
$('input[name="id"]').val(id);
$('input[name="status"]').val(status);// use in modal right
}
function show_modal(obj) {
var modal_id = $(obj).attr('href');
var content = $(modal_id).children('div.modal-dialog').children('div.modal-content');
var data_url = $(obj).attr('data-url');
$.ajax({
url: data_url,
dataType: "html",
catch : false,
success: function (data) {
$(content).html(data);
}
});
}