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>
Edited by fluidsharp
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.