Welcome Guest, Not a member yet? Register   Sign In
POST empty when called from another method
#1

[eluser]sico87[/eluser]
On my website I am using ajax post request to show content around my site, this is done using this code,
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,

Code:
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,

Code:
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?
#2

[eluser]Flemming[/eluser]
how does the $_POST variable get its value set?

EDIT: I should read properly before posting
#3

[eluser]sico87[/eluser]
It gets set in the ajax, it definatly gets set becuase i do checks on it in another method, the get_content_abstract method above, and both the checks get results, but when I try and access
Code:
$this->input->post()
in my love this method I get an empty array
#4

[eluser]Flemming[/eluser]
ah yes, sorry - I misunderstood! Have you tried hard-coding a value for url in your javascript?

and are you using firebug to see what is actually getting sent in the POST?
#5

[eluser]Monarobase[/eluser]
Edit : sorry wrong topic !
#6

[eluser]sico87[/eluser]
[quote author="Flemming" date="1263322386"]ah yes, sorry - I misunderstood! Have you tried hard-coding a value for url in your javascript?

and are you using firebug to see what is actually getting sent in the POST?[/quote]

Ye it is all going into the post fine according firebug, it is very strange I thought the post was Super Global?
#7

[eluser]Flemming[/eluser]
Quote:public function love_this() {
die(var_dump($this->post->input('url')));
}

could be a typo?

it should be
Code:
$this->input->post

?
#8

[eluser]sico87[/eluser]
it is a typo but I fixed that in my code but not in this example is not that unfortunatly Sad
this is so frustrating there is no reason why I should not be able to access the POST in all my methods is there?
#9

[eluser]Flemming[/eluser]
errrrm... are you posting TO the love_this method or are you posting to another method and then trying to access the POST data in love_this ?
#10

[eluser]sico87[/eluser]
I am posting to another method and then trying to access it from love_this, are you about to tell me that that is impossible?




Theme © iAndrew 2016 - Forum software by © MyBB