我正在尝试使用ajax将数据插入数据库,但我需要加载页面以便在浏览器中更新我桌面上的数据。在创建或更新后,我可以看到我的pag加载,但我仍然需要再次加载我的页面以查看我的表格上的结果
form.php的
<form action="<?php echo site_url($action); ?>" method="post">
<div class="ibox-content gbItemHolder divider">
<div class="form-group">
<label>Disposition Name</label>
<input type="text" name="disposition_name" id="disposition_name" placeholder="Disposition Name" class="form-control mBottom2 " value="<?php echo $disposition_name; ?>">
<?php echo "<p>".form_error('disposition_name')."</p>" ?>
<label>Disposition Code</label>
<input type="text" name="disposition_code" id="disposition_code" placeholder="Disposition Code" class="form-control mBottom2 " value="<?php echo $disposition_code; ?>"><?php echo "<p>".form_error('disposition_code')."</p>" ?>
<label>Disposition Email</label>
<div id="tags">
<input type="text" name="email" id="email" placeholder="Enter Email here" class="form-control mBottom2 " value="<?php echo $email; ?>"><!-- <?php echo "<p id='email_validation'>".form_error('disposition_code')."</p>" ?> -->
</div>
<input type="text" id="tenant_id" name="tenant_id" value="<?php echo $tenant_id; ?>" hidden="true">
<input type="hidden" id="calldisp_id" name="calldisp_id" value="<?php echo $calldisp_id; ?>" />
</div>
<div style="margin-top:10px;">
<input type="hidden" name="calldisp_id" value="<?php echo $calldisp_id; ?>" />
<button type="submit" class="btn btn-md btn-primary m-t-n-xs" id="triger" value = "<?php echo $button; ?>"><?php echo $button; ?> Call Disposition</button>
<a href="<?php echo site_url('admin/call_disposition') ?>" class="btn btn-md btn-warning m-t-n-xs">Cancel</a>
</div>
</div>
</form>
js_files_includes.php
$('#triger').click(function(){
var btn_value = $('#triger').val();
var tenant_id = $('#tenant_id').val();
var calldisp_id = $('#calldisp_id').val();
var disposition_name = $('#disposition_name').val();
var disposition_code = $('#disposition_code').val();
var email = $.map($("#tags span"), function(elem, index){
return $(elem).text();
});
var myJsonString = JSON.stringify(email);
//alert(myJsonString);
if(btn_value == 'Create'){
$.ajax({
url:"<?php echo base_url(); ?>admin/call_disposition/create_email_dispo_dre",
method:"POST",
data:{email:myJsonString,
disposition_name:disposition_name,
disposition_code:disposition_code,
tenant_id:tenant_id},
dataType: 'json',
success:function(data){
toastr.success("Call Disposition Successfully Created");
},
});
}
else if(btn_value == 'Update'){
$.ajax({
url:"<?php echo base_url(); ?>admin/call_disposition/update_email_dispo_dre",
method:"POST",
data:{email:myJsonString,
disposition_name:disposition_name,
disposition_code:disposition_code,
calldisp_id:calldisp_id,
tenant_id:tenant_id},
dataType: 'json',
success:function(data){
toastr.success("Call Disposition Successfully Updated");
},
});
}
});
call_disposition.php
public function create_email_dispo_dre($id){
$this->_rules();
if ($this->form_validation->run() == FALSE) {
$this->update($id);
} else {
$data = array(
'tenant_id' => $this->input->post('tenant_id',TRUE),
'disposition_code' => $this->input->post('disposition_code',TRUE),
'disposition_name' => $this->input->post('disposition_name',TRUE),
'email' => $this->input->post('email',TRUE)
);
$this->calldisp_model->insert($data);
redirect('admin/call_disposition/update/'.$id);
}
}
public function update_email_dispo_dre(){
$data = array(
'calldisp_id' => $this->input->post('calldisp_id',TRUE),
'disposition_name' => $this->input->post('disposition_name',TRUE),
'disposition_code' => $this->input->post('disposition_code',TRUE),
'email' => $this->input->post('email',TRUE),
'tenant_id' => $this->input->post('tenant_id',TRUE)
);
$this->calldisp_model->update($this->input->post('calldisp_id', TRUE), $data);
redirect('admin/call_disposition/update/');
}
答案 0 :(得分:1)
您可以使用
location.reload();
在你的成功功能中。
答案 1 :(得分:0)
使用refresh
redirect('admin/call_disposition/update/'.$id,"refresh");
redirect('admin/call_disposition/update/', "refresh");