Welcome Guest, Not a member yet? Register   Sign In
Ajax Record Deletion?
#1

[eluser]Corey Freeman[/eluser]
Hey everyone!

I managed to figure out how to add a record via ajax using the following function:

Code:
[removed]
$(document).ready(function() {
$('#new-goal-submit').click(function() {
var msg = $('#new-goal-input').val();
$.post("<?= site_url('dashboard/add') ?>", {message: msg}, function() {
    $('#dashboard').load("<?= site_url('dashboard/ajax') ?>");
    $('#new-goal-input').val('');
});
});
});
[removed]

What I want to know is how I can delete a record also by using ajax. There's not a dynamically generated ID to account for when adding, so I'm kind of stumped. >.<

Help? Smile
#2

[eluser]Corey Freeman[/eluser]
Okay so this actually isn't working at all...my browser is just reloading super fast. Here's my controller too:

Code:
&lt;?
class Dashboard extends Controller
{
    function Dashboard()
    {
        parent::Controller();
        $this->load->library('Jquery_pagination');
        $this->load->model('goals_model');
    }
    function index($type = NULL) {
        //Load the Header
        $data['title'] = 'Your Nimblu Goals Dashboard';
        $this->load->view('templates/dash_header', $data);
        //Load up 'dem dere goals!
        ///////////////////////////////////////////////////////////
            $total = $this->goals_model->count_user_goals();
            $config['base_url'] = site_url('dashboard/index/2/');
            $config['total_rows'] = $total;
            $config['per_page'] = 5;
            $config['div'] = 'body';
            $config['uri_segment'] = '4';
            $config['full_tag_open'] = '<div id="pagination">';
            $config['full_tag_close'] = '</div>';
            //Previous
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span class="prev">';
            $config['prev_tag_close'] = '</span>';
            //Next
            $config['next_link'] = 'Next';
            $config['next_tag_open'] = '<span class="next">';
            $config['next_tag_close'] = '</span>';
            $this->jquery_pagination->initialize($config);
            $data['goals'] = $this->goals_model->get_user_goals(5, $this->uri->segment(4));
        ///////////////////////////////////////////////////////////
        //Is Ajax Being Used?
        if ($type == "ajax") {$this->load->view('dashboard/goals', $data);}
        //Load a Normal View
        else {$this->load->view('dashboard/default', $data);}
        //Load the Footer
        $this->load->view('templates/footer');
    }  
    function add_goal()
    {
    if($_POST && $_POST['goal'] != NULL) {
        $message['goal_text'] = $this->input->xss_clean($_POST['goal']);
        $message['owner_id'] = $this->input->post('owner_id');
        $message['complete_status'] = $this->input->post('complete');
        $this->goals_model->add($message);
    } else
        redirect('dashboard');
    }
    function delete_goal() {
        $this->goals_model->delete_user_goal();
    }
}
#3

[eluser]alexaaaaaaaaaa[/eluser]
don't use $_post use $this->input->post('field_name');
here's a simple example on how to do it

$(document).ready(function() {
$("a.link_class").click(function (event) {
event.preventDefault();
if (confirm('Are you sure? ')){

var del_id = $(this).attr('id');
$.post("index.php/Dashboard/delete_goal", {item_id : del_id}, function(data){

// succcess??
}); }
}); });
//here's the loop foreach ($whatever as $me)
{
&lt;?= anchor('#', 'Delete', array('class' =>'link_class', 'id'=>$something->id)); ?&gt;
}




Theme © iAndrew 2016 - Forum software by © MyBB