Welcome Guest, Not a member yet? Register   Sign In
jquery post
#1

[eluser]marjune[/eluser]
ei pipz, my script in jquery using post didn't work!!


my jq script

Code:
$(".topicans").click(function(){                
      var topic_id = $('.topic_id',this).val();                    
      $.post('controller/controller_function', {id: topic_id});
});
#2

[eluser]eric cumbee[/eluser]
ive found that using base_url() in your .post url works alot better, some times it worked for me with it other times it didnt.
#3

[eluser]marjune[/eluser]
i already try this but nothing's happen
Code:
$.post("<?php base_url().'furoms/viewthread' ?>", {topic: topic_id});
#4

[eluser]Ben Edmunds[/eluser]
Try this:

Code:
$.post("<?php echo base_url();?>furoms/viewthread", {topic: topic_id});


You have to echo the base_url() function as it doesn't output automatically.
#5

[eluser]marjune[/eluser]
i try but nothing

Code:
$.post("<?php echo base_url();?>furoms/viewthread", {topic: topic_id});
#6

[eluser]Ben Edmunds[/eluser]
What is the error your getting? No response?

Please post your controller that this posts to.


Thanks,
#7

[eluser]marjune[/eluser]
no response !

my controller

Code:
function viewthread(){
    $this->load->helper('form');
    $this->load->helper('url');
    $topic_id = $this->input->post('topic');
    $thread['data'] = $this->furom->furomthread($topic_id);
    $this->load->vars($thread);
    $this->load->view('thread');
     }
#8

[eluser]Ben Edmunds[/eluser]
Alright,

So your doing:

Code:
$(".topicans").click(function(){                
      var topic_id = $('.topic_id',this).val();                    
      $.post('<?php echo base_url();?>controller/viewthread', {topic_id: topic_id});
});

and then what do you want to happen? You need to add the data callback on your post function if you want to display something.

For example:

Code:
$(".topicans").click(function(){                
      var topic_id = $('.topic_id',this).val();                    
      $.post('<?php echo base_url();?>controller/viewthread', {topic_id: topic_id}, function(data) {
           $('#contentYouWantToChange').append(data);
            }, 'text');
});

Also note, your posting id but your controller is expecting topic_id.
#9

[eluser]marjune[/eluser]
i dont want a call back! what i want to happen is after posting the data from jquery, i let the the controller to do the thing

here

Code:
function viewthread(){
     $this->load->helper('form');
     $this->load->helper('url');
     $topic_id = $this->input->post('topic_id');
     $thread['data'] = $this->furom->furomthread($topic_id);
     $this->load->vars($thread);
     $this->load->view('thread');
}

to the next view('thread');
#10

[eluser]Ben Edmunds[/eluser]
Well the post function is doing an ajax request so I think one of us is misunderstanding something...

Are you wanting to load a different page when topicans is clicked? If so, why not just use a link like href="controller/viewthread/1"?

For reference, http://docs.jquery.com/Ajax/jQuery.post




Theme © iAndrew 2016 - Forum software by © MyBB