I’m trying to figure out why when it gets gets to the getLast5Messages function in my controller it returns the following but in the response in the javascript it puts the html of the page. I don’t get it.
[{"id":"1","subject":"Testing","firstName":"Kevin","lastName":"Smith","dateSent":"March 30th, 2012","messageRead":"0"}]
js:
function getMessages()
{
$('.mail').empty();
$.get('dashboard/getLast5Messages', function(data)
{
if(data.length > 0)
{
$.each(data, function(x)
{
if (data[x]['messageRead'] == 0)
{
$('.mail').append('<li><a href="pmsystem/viewmessage/'+data[x]['id']+'"><strong>Received: '+data[x]['dateSent']+'</strong><small>'+data[x]['subject']+'</small><small>From: '+data[x]['firstName']+' '+data[x]['lastName']+'</small></a></li>');
}
else
{
$('.mail').append('<li class="read"><a href="pmsystem/viewmessage/'+data[x]['id']+'"><strong>Received: '+data[x]['dateSent']+'</strong><small>'+data[x]['subject']+'</small><small>From: '+data[x]['firstName']+' '+data[x]['lastName']+'</small></a></li>');
}
});
}
else
{
$('.mail').append('<li>No Messages</li>');
}
}, 'json');
}
php:
public function getLast5Messages()
{
echo $this->pmmodel->getLast5Messages($this->session->userdata('userID'));
}
/**
* Retrieve last 5 messages in inbox
*
* @param integer
* @return object
*/
function getLast5Messages($userID)
{
// Check args
if (!is_numeric($userID))
{
throw new Exception('Non-numeric $userID provided to getLast5Messages()');
}
$this->db->select('pm.id');
$this->db->select('pm.subject');
$this->db->select('users.firstName');
$this->db->select('users.lastName');
$this->db->select("DATE_FORMAT(pm.dateSent, '%M %D, %Y') AS dateSent", false);
$this->db->select('pmr.messageRead');
$this->db->from('usersPersonalMessages AS pm');
$this->db->join('users', 'users.userID = pm.senderID');
$this->db->join('usersPersonalMessagesRecipients AS pmr',
'pm.id = pmr.usersPersonalMessagesID');
$this->db->where('pmr.userID', $userID);
$this->db->order_by('pm.dateSent', 'desc');
$this->db->limit(5);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
return $query->result();
}
return array();
}
I’m still not able to figure this out? Does anyone have any idea what could be causing this?
It was