[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 : '<?=base_url();?>index.php/kids/getpic/<?=$id?>',
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:
<?php if($profilepic!=""){
echo img(array('src'=>$profilepic,'border'=>'1'));
}else{
echo img(array('src'=>'img/nopic.png','alt'=>'nopic','border'=>'1'));
}
?>
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