Please look at this code:
$('ul#navigation li ul li>a').click(function(){
var active = $(this).text();
$('#artcontent p').empty();
$.ajax({
type: 'POST',
url: 'homepage/readarticle',
data: $(active).serialize(),
success: function(databack){
$('#loading').fadeOut('normal');
$('#artcontent').append(databack);
}
})
});
function readarticle()
{
$articlename = $this->input->post('active');
$output = $this->articles->displayby_name($articlename);
if($output){
$data['article'] = $output;
}
$this->load->view('loadarticle',$data);
}
This is the function that is on the server.
I have a ul li a that are children of parent ul navigation and li. What I am trying to do is to load an article page. This works but it reads the database and loads all the articles in my database instead of the one identified by active. I would like to know what I am doing wrong or is there a better way to go about this?
OK, the 'homepage/readarticle' is the 'controller/method' in my CodeIgniter controller which loads the view that renders the article.
As for the serialize line, I actually put in active without the serialize and could catch the text of the link with Firebug using the usual console.log(). Like I said, it reads the articles all right, but it reads all the articles from my database instead of fetching the one whose title is equal to the name in the active variable (that would be the text of the link so, for example, <a href="#">see this</a>. See this is the text.)
OK, let me add the code that handles this also from the model which is the last piece in:
<?php
function displayby_name($name) { $this->db->select("articletitle,articlebody,articleauthor");
$this->db->from('articles'); $this->db->where('articletitle',$name);
$Q = $this->db->get(); if($Q->num_rows() > 0){ $text = $Q->result_array(); }
echo $this->db->last_query();
return $text; }
?>
Any thoughts still?