Welcome Guest, Not a member yet? Register   Sign In
jQuery, Add / Delete elements without page refresh
#9

[eluser]Chris Newton[/eluser]
Ok. I've been trying on and off for a few days, but I'm not getting anywhere on this. Thus far, you guys have been really helpful, but every method I've tried hasn't yielded me any results. I'll post my code, and would be grateful to anyone that can provide any insight into the errors. I've stepped the code down to the bare essentials to reduce any bugs. I'd love to get some kind of error at a minimum, but so far I've been unable to see any action whatsoever.

1. Controller: test_controller.php
Code:
<?php
class Test_controller extends Controller {

    function Test_controller(){
        parent::Controller();

    }
    function index(){
    $data['title']='test';
        $this->load->view('admin_delete_this_view',$data);
    }
        
}            
            
?>

2. View admin_delete_this_view.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;test&lt;/title&gt;
    
    
    $('.delete').click(function(){
    $.ajax({
       type: "POST",
       url: "/index.php/test_ajax_controller/delete",
       data: "id="+$(this).prev().text(),
       success: function(html){
           $("#show").html(html);
           }
    });
    return false
    });
    
&lt;/head&gt;

&lt;body&gt;
<table>
<tr><td>filename</td><td>other info</td><td><span class="hidden">3</span>&lt;input type="submit" class="delete" value="delete"&gt;</tr>
</table>
<br />
<br />
<p>
<div id="show"></div>
</p>
&lt;/body&gt;

3. Ajax controller. test_ajax_controller.php
If the $_POST['id'] is hard coded to a known database id, and called directly it works.

Code:
&lt;?php
class Test_ajax_controller extends Controller {

    function Test_ajax_controller(){
        parent::Controller();
    }
    function delete(){
        $data['delete_me']=$_POST['id'];
    
        if (!empty($data['delete_me'])){
            $this->load->model('properties', '', TRUE);
            $this->properties->deleteElevations($data['delete_me']);
            $this->output->set_output('works');
        } else {
            $this->output->set_output('dontwork');

        }
    }
}    
                
            
?&gt;

4. Model snippet from properties.php (which will work if called via other methods)
Code:
function deleteElevations($id){
        $this->db->delete('elevations', array('id' => $id));
    }


Messages In This Thread
jQuery, Add / Delete elements without page refresh - by El Forum - 10-29-2007, 09:35 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-29-2007, 10:49 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-30-2007, 12:30 AM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-30-2007, 07:13 AM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-30-2007, 09:35 AM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-30-2007, 07:02 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-30-2007, 10:41 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 10-30-2007, 10:49 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 11-06-2007, 11:46 AM
jQuery, Add / Delete elements without page refresh - by El Forum - 11-06-2007, 12:29 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 11-06-2007, 12:38 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 11-06-2007, 12:42 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 11-06-2007, 01:09 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 11-06-2007, 01:29 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 06-02-2009, 08:02 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 06-02-2009, 09:04 PM
jQuery, Add / Delete elements without page refresh - by El Forum - 06-03-2009, 12:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB