我想使用jquery

时间:2016-03-10 08:03:06

标签: javascript jquery mysql codeigniter

这是我的视图页面...... 在这里,我的图像没有被删除。当我发出警报并且没有被删除时,图像名称没有警报..

 <div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-body">
                   Are you sure you want to delete this image? 
                  </div>

                  <div class="modal-footer">

                    <input type="hidden" name="image" id="img">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="modal-close">Close</button>
                    <button type="button" class="btn btn-danger" id="delete-ok">Ok</button>
                  </div>
                </div>
              </div>
            </div>


<script type="text/javascript">
    $(document).ready(function (){
    $('#modal-close').click();
       $("#file").change(function() { $('#upload-image').submit(); });
        $('#upload-image').on('submit',(function(e){
           e.preventDefault();
           //alert()
            var formData = new FormData(this);
            $.ajax({
                type:'POST',
                url: $(this).attr('action'),
                data:formData,
                cache:false,
                contentType: false,
                processData: false,
                success:function(result)
                {
                   //$('#uploaded-img').html(result);
                    //location.reload();
                }
            });
        }));

        $(".fa-close").click(function(){
            var image=$(this).attr('image');
           alert(image);
           $("#img").val(image);
        });

      $("#delete-ok").click(function(){
            var image=$("#img").val();
            alert(image);

            var url='<?php echo base_url(); ?>admin_control/delete_upload_image';
            alert(url);
            var id=$("#product_id").val();
            alert(id);

            $.post(url, {image:image,id:id}, function(result)
                  {
                    //$('#uploaded-img').html(result);
                    location.reload();

                  });


        });

      });

我的控制器页面就是这个......

public function delete_upload_image()
{   

if($_POST)
{
  $data=$this->session->userdata('image');

  $f=$this->input->post('image'); 
  $this->edit_image_delete($f);

  unset($data[array_search($f,$data)]);
  $this->session->set_userdata('image',$data);

    var_dump('$data');

  /*for editing */
  if($this->input->post('id'))
  {
      $image=array_values($this->session->userdata('image'));
      $data=array('image'=>json_encode($image));

    if($this->input->post('table')=='gallery')
    {
      /*update gallery table*/
      $this->roxmodel->update_gallery($this->input->post('id'),$data);
    }
    else
    {
      /*update product table*/
      //$this->adminmodel->update_product($this->input->post('id'),$data);
    }

  }
  $this->load->view('admin_control/ajax_show_upload_image',$data);
}

}

 public function edit_image_delete($image)
  {


  if(file_exists('images/'.$image))
  {
    @unlink("./images/".$image);
  }
  if(file_exists('images/thumb/'.$image))
  {
    @unlink("./images/thumb/".$image);
  }
  return true;  
}

这里我的图片没有被删除。当我发出提醒并且没有被删除时,图片名称没有提醒..

0 个答案:

没有答案