views:

266

answers:

1

On my website I am using ajax post request to show content around my site, this is done using this code,

$("a.contentlink").click(function(ev) {
    ev.preventDefault();
    $('#main_menu').hide();
    var url = $(this).attr("href");
    var data = "calltype=full&url="+url;
    $.ajax({
        url:url,
        type: "POST",
        data: data,
        success : function (html) {
            $('#left-content-holder').html(html);
        }
    })
});

as you can see I am passing the url into the `$_POST' and I can access this in the method the javascript calls, this method is called get_content_abstract and looks like this,

public function get_content_abstract() {

    $this->load->model('content_model');
    if($this->input->post('calltype') == "abstract"){
        if($query = $this->content_model->get_content_by_id($this->uri->segment(3))) {
            $data['abstract'] = $query;
        }
        $this->load->view('template/abstract', $data);
    }
        elseif($this->input->post('calltype') == "full") {
            if($query = $this->content_model->get_content_by_id($this->uri->segment(3))) {
                $data['full'] = $query;
            }
            $this->load->view('template/full-content', $data);
        }

}

How ever I have no added a new function that will allow the user to save the content to 'bookmarking system', however in my method I cannot access the post using codeigniters $this->input-post('url') (where URL is the one of peices of data passed in the javascript), it says that the post is empty when I var dump it, this is done using this method,

    public function love_this() {
    die(var_dump($this->post->input('url')));
}

can anyone help as to why the post is empty in this love_this method?

+1  A: 

Shouldn't:

public function love_this() {
    die(var_dump($this->post->input('url')));
}

Actually be

public function love_this() {
    die(var_dump($this->input->post('url')));
}

See:

http://codeigniter.com/user_guide/libraries/input.html

Sean Vieira
He's right you know.
Phil Sturgeon
He is indeed, I would say it was a delibrate mistake, but I think that makes me look worse.
sico87
@sico87 ... was that just a copy / paste error, or did that fix the problem?
Sean Vieira
It was just a copy and paste error, the problem was really no existent, after I had thought about long and hard, the POST was unavailbale as it was made in a different method via javascript so I had to change how the system works, all is good now :-) thanks for looking over it
sico87