如果在代码点火器中使用 Ajax 成功更新,则发出警报
alert if success update using ajax in codeigniter
请帮帮我。我是阿贾克斯的新手。我正在使用代码点火器。我正在使用javascript模式(警报)来显示我是否成功删除了数据。
以下是我的观点:
<script type="text/javascript">
$(document).on("click", ".delete-data", function () {
var id = $(this).data('id');
$("#id").val( id );
});
</script>
<div class="down1">
<button type="button" class="button-orange" onclick="add_child();" id="child_add">Add</button>
</div>
<div class="span11 offset1" id="childdv">
<?php echo $child_set;?> <!--this one shows that table of children-->
</div>
the modal delete
<!--delete-->
<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-haspopup="true" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="alert alert-danger fade in" id="alert">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Heads Up!</h3>
<p>What you are doing will delete a data!</p>
<input type="hidden" name="id" id="id" value=""/>
<a onclick="delete_child();" id="okButton" class="btn btn-danger" data-dismiss="modal">
Confirm Delete
</a>
<a href="#" class="btn" data-dismiss="modal">
Cancel
</a>
</div>
</div>
</div>
</div>
我的主控制器显示
$data_set['record_set'] = $this->emp->get_children($id);
$data['employee_header_menus'] = $this->load->view('employee_header_menus', NULL, TRUE);
$data['employee_header_logout'] = $this->load->view('employee_header_logout', NULL, TRUE);
$data['child_set'] = $this->load->view('swoosh_template/employee/child', $data_set, TRUE); //<--- you can see in here that the $child_set came from here.
$data['info'] = $this->emp->get_myinfo($id);
$data['msg'] = "";
$data['color'] = "green";
$data['header_logo'] = $this->load->view('header_logo', NULL, TRUE);
$this->load->view('employee/personaldetails', $data);
现在。那child_set在哪里,这是一个视图。
<?php if ($record_set !="" ) { ?>
<table id="tblcount" class="table table-bordered">
<tr class="orange">
<th>Name</th>
<th>Date of Birth</th>
<th>Dependent</th>
<th>Delete</th>
</tr>
<?php foreach ($record_set as $row): ?>
<tr>
<td>
<?php echo $row[ 'name'];?>
</td>
<td>
<?php echo $row[ 'birth_date'];?>
</td>
<td>
<?php echo ($row[ 'dependent']=='1' ? 'Yes': 'No');?>
</td>
<td>
<img data-toggle="modal" data-id="<?php echo $row['id']?>" class="delete-data" href="#delete" style="cursor:pointer" height="15" width="15" src="<?php echo base_url(); ?>images/remove.gif">
</td>
</tr>
<?php endforeach?>
</table>
这是我调用模态的JavaScript。
function delete_child()
{
var id = $("#id").val();
if (id!=null){
swoosh(id, path+'swoosh_employee/swoosh_delete_child', 'childdv'); //<-- this is the function that calls my controller
$('#success').modal('show'); // <-- this is the alert.
}
}
但我不想把警报放在那里。 因为我想先验证我的控制器中的函数是否成功运行。 这就是我将显示该警报的时间。
这是我的控制器:
public function swoosh_delete_child()
{
$P1 = $this->session->userdata('id');
parse_str($_SERVER['QUERY_STRING'],$_GET);
$id = $_GET['h'];
$this->emp->delete_children($id); // <-- in here , i want to validate this. if successful: alert success, else alert error
$set['record_set'] = $this->emp->get_children($P1);
$this->load->view('swoosh_template/employee/child',$set);
}
这是模型:
public function delete_children($P1)
{
$this->db->delete('employee_children', array('ID' => $P1));
}
现在,我想做的是。"阿贾克斯"..这将检查函数是否成功运行或我是否成功删除,例如:
if success{
$('#success').modal('show');
}
else{
$('#error').modal('show');
}
我一直在寻找如何使用ajax。 但我似乎无法理解它。我只是编程新手。平均。
试试这个:
更新
型:
public function delete_children($P1,$id)
{
$delete = $this->db->delete('employee_children', array('ID' => $P1,'child_id' => $id));
if ($delete){
return "success";
}
else{
return "failed";
}
}
控制器:
public function swoosh_delete_child()
{
$P1 = $P1 = $this->session->userdata('id'); // get the parent id
$id = $this->input->post('id'); // get child id
$delete = $this->emp->delete_children($P1,$id); // delete the child of current parent
if($delete == "success"){
echo $delete;
}
else{
echo $delete;
}
}
我曾经使用过这个 ajax:
function delete_child()
{
var id = $("#id").val();
if (id!=null){
$.ajax({
url : "<?php echo base_url('swoosh_employee/swoosh_delete_child') ?>",
data : "id="+id,
type: "POST",
success :
function (data){
if (data == "success"){
alert("delete success");
}
else{
alert("delete failed");
}
}
});
}
}
要显示此父项的子项,可以构建另一个 ajax。
相关文章:
- Ajax POST返回成功,但没有;t更新JSON文件
- 如何在alt.js中使用源成功请求后更新状态
- 成功回调中的外部变量未正确更新
- 如何使用错误消息或成功消息动态更新我的跨度
- 当通过Ajax成功回调更新可观察数组时,启用绑定中断
- 如何判断Realm是否已成功更新
- 从AJAX成功函数更新图像源
- 随着Ajax的成功,投票计数器更新
- 如何在Firebase中更新后返回成功数据
- X-可编辑在成功更新后放置“空”
- AngularJS:在成功的HTTP请求后更新指令范围
- 如果在代码点火器中使用 Ajax 成功更新,则发出警报
- 在代码点火器中使用 AJAX 单击按钮时,成功更新后显示确认
- $scope变量在控制器中没有更新,在成功的$http GET请求中
- Ajax返回成功,但未更新数据库
- 主干更新触发完成,但不会触发错误或成功
- 在成功调用ajax之后更新引导popover的内容
- Struts Javascript AJAX成功页面更新<脚本>援引
- 如何从KML文件中将一对融合表与GroundOverlays集成?更新了我试图解决的问题(未成功)
- 如何在更新成功之前禁用某些控件