Welcome Guest, Not a member yet? Register   Sign In
Ajax periodical refresh using jquery
#1

[eluser]hackersapien[/eluser]
I've implemented using codeigniter and jquery, a periodic refresher that basically reloads a div every few seconds. The javascript is working well and using firebug I can see the request being sent and the response, the only problem is that the <div> in my view isn't loading the response, I'm not sure its a javascript problem since firebug has no errors so I think its a problem with the CI code.

Javascript
Code:
function callMeOften()
{
      $.ajax({
                    method: 'get',
                    url : '&lt;?=base_url();?&gt;index.php/kids/getpic/&lt;?=$id?&gt;',
                    dataType : 'text',
                    success: function (text) { $('updateMe').html(text); }
                 });

}

var holdTheInterval = setInterval(callMeOften, 5000);

CI Controller Code

Code:
function getpic($id=null)
    {
        $data['profilepic']=$this->profilepicture->getProfilePic($id);
        $this->load->view('kids/getpic',$data);
    }
CI View Code- getpic.php
Code:
&lt;?php if($profilepic!=""){
    echo  img(array('src'=>$profilepic,'border'=>'1'));
}else{
    echo  img(array('src'=>'img/nopic.png','alt'=>'nopic','border'=>'1'));
}
?&gt;

If you got any idea where i'm going wrong, please assist me.
#2

[eluser]Pascal Kriete[/eluser]
Your jQuery selector isn't valid. Probably missing a # if you're using the div's id.
#3

[eluser]ggoforth[/eluser]
[quote author="hackersapien" date="1225420921"]I've implemented using codeigniter and jquery, a periodic refresher that basically reloads a div every few seconds. The javascript is working well and using firebug I can see the request being sent and the response, the only problem is that the <div> in my view isn't loading the response, I'm not sure its a javascript problem since firebug has no errors so I think its a problem with the CI code.

Javascript
Code:
function callMeOften()
{
      $.ajax({
                    method: 'get',
                    url : '&lt;?=base_url();?&gt;index.php/kids/getpic/&lt;?=$id?&gt;',
                    dataType : 'text',
                    success: function (text) { $('updateMe').html(text); }
                 });

}

var holdTheInterval = setInterval(callMeOften, 5000);

CI Controller Code

Code:
function getpic($id=null)
    {
        $data['profilepic']=$this->profilepicture->getProfilePic($id);
        $this->load->view('kids/getpic',$data);
    }
CI View Code- getpic.php
Code:
&lt;?php if($profilepic!=""){
    echo  img(array('src'=>$profilepic,'border'=>'1'));
}else{
    echo  img(array('src'=>'img/nopic.png','alt'=>'nopic','border'=>'1'));
}
?&gt;

If you got any idea where i'm going wrong, please assist me.[/quote]

If you are seeing the response in Firebug then there isn't anything wrong with CI. I would say it's your jQuery selector. You are selecting:

$('updateMe') where I think you mean $('#updateMe') or $('.updateMe'). The selector is CSS based so you need to select the id. That selector is looking for an html tag named updateMe.

Hope that helps.

Greg




Theme © iAndrew 2016 - Forum software by © MyBB