ajax - jQuery-Codeigniter. Deleting second picture fail -


i have page selected product , pictures. want delete data pictures db , folders , update page via jquery ajax.

firstly try using <a href> , can delete 1 picture updating page successfully, after url changed (to end added '#'), script stopped sending (this part commented, can find below )

secondly added button , use .click(), .on event. first picture deletes second not, deletes after refreshing. second attempt - nothing change, button without event.

controller main.php:

       function del_image($picture_id){               $this->load->model('admin/product_crud');             $data['picture_name'] = $this->product_crud->get_picture_name($picture_id);             //var_dump($data);              unlink('uploads/100/'.$data['picture_name'][0]->url);               $data['product_id'] = $this->product_crud->find_product_id_from_picture($picture_id);              $this->product_crud->del_picture_from_db($picture_id);             $data['picture'] = $this->product_crud->get_picture($data['product_id'][0]->product_id);              $update_html = $this->product_crud->create_picture_output($data['picture']);             echo json_encode($update_html);                  //$this->output->enable_profiler(true);          } 

model product_crud.php:

      function create_picture_output($pictures){          $output = null;          $output .="<table border='1'>";           foreach ($pictures $picture){                $output .=  "<tr>";               $output .= "<td><a class='del_picture'  href='".$picture->picture_id."'><img title='Удалить' src='".base_url()."images/del.png'> </a></td>               <td><img src='".base_url()."uploads/100/".$picture->url."'></td>                <td><input class='del_picture' type='button' name='del'  value='".$picture->picture_id."'><img title='Удалить' src='".base_url()."images/del.png'> </td>";                        $output .= "</tr>";          }            $output .="</table>";            return $output;         } 

view form_edit_product.php ...............

       echo "<div id='result_table'>";         echo "<table border='1'>";          foreach ($url $picture){         echo "<tr>";        echo "<td><a class='del_picture' href='".$picture_id[$l]."'><img             title='Удалить' src='".base_url()."images/del.png'></a></td>               <td><img src='".base_url()."uploads/100/".$picture."'></td>               <td><input class='del_picture' type='button' name='del' value='".$picture_id[$l]."'><img title='Удалить' src='".base_url()."images/del.png'></td>";             $l++;             echo "</tr>";          }             ?>           </table>          </div> 

script:

   $(".del_picture").on("click", function(){      /* var picture_id =  $(this).attr("href");         var myurl = '<?php echo base_url()."admin/main/del_image/"?>';          $(this).attr("href",'#'); */           var picture_id =  $(this).attr("value");           var myurl = '<?php echo base_url()."admin/main/del_image/"?>';            var url = myurl + picture_id        $.ajax({         url: url,         type:'get',         datatype: 'json',         success: function(update_html){                 $("#result_table").html(update_html);              }          });          }); 

issue somewhere url/jquery script/get. may after updating event not adding button...

you can use ajax if want don't have to. there's way. in controller @ end of del_image() method after line:

$this->product_crud->del_picture_from_db($picture_id); 

put code

$ref = $this->input->server('http_referer', true); redirect($ref, 'location'); 

this last url , refresh page after photo has been deleted. don't need update html , no json needed.

if want to, can use ajax too, there's mistakes have in code. example, need delete datatype json since using request. when creating url, missing semicolon before ending php statement.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -