Jump to content

jQuery.AJAX - Codeigniter second call is not executed.


fluidsharp

Recommended Posts

Hi,

 

I have issue with deleting data via jquery/ajax. First delete execute and data on page changed. But then when I click on next element for deleting, nothing happens.

To avoid complicated code I wrote simple example which demonstrate issue.

 

 

 

Controller

function test_contr(){
   $this->load->model('admin/Product_crud');
   $data['query']=$this->Product_crud->test_model_select_data();
   $this->load->view('admin/test',$data);
   
}

function test_delete($id){
   $output = NULL;
   //var_dump($id);
   $this->load->model('admin/Product_crud');
   $this->Product_crud->test_delete($id);
   $data['query']=$this->Product_crud->test_model_select_data();
   
   foreach($data['query'] as $row){
      $output .= $row->id."<input class='del_picture' type='button' value='".$row->id."' name='id'>";
   }
  
    echo json_encode($output);
  
   
}



Model
not needed as there simple select id from database and delete







View
<!DOCTYPE html>
<html>
   <head>
   <META http-equiv="Content-Type" content="text/html; charset=utf-8">   
   <script src="/script/jquery-1.9.1.min.js"></script>
   </head>
<body>
   
   
<div class="result_table">
   
<?php
foreach ($query as $row){
   echo $row->id."<input class='del_picture' type='button' value='".$row->id."' name='id'>";
}
?>  
</div>
</body>
</html>

<script>
$(".del_picture").on("click", function(){
  
   var id =  $(this).attr("value");
     var myurl = '<?php echo base_url()."admin/main/test_delete/"?>';
     
    var url = myurl + id;
    $.ajax({
            url: url,
            type:'GET',
            dataType: 'json',
            
            success: function(update_html){
                    $(".result_table").html(update_html);
                     
                } 
            });    
   
});
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.