Welcome Guest, Not a member yet? Register   Sign In
jquery (ajax) post to controller to model (and back) to view problem
#5

[eluser]steelaz[/eluser]
As I mentioned, you need to tell jQuery what to do with this data. For example, to update your div you can do this:

Code:
$(document).ready(function() {
    $('a').click(function(){
        $.post('http://markandersjohnson.com/CodeIgniter_1.7.2/index.php/blog/change_lyrics', { id: this.name}, function(data){
            $('#top_post').html(data);
        });
     });
});

Notice the last parameter in $.post is a function. This function accepts returned data as parameter, then in this function div id="top_post" contents are replaced with returned data.

Since your change_lyrics function is loading the whole page, you should create new function, that only loads lyrics text. Perhaps something like this:

Code:
function ajax_lyrics() {
      $data['title'] = 'Lyrics';
      
      $song_id = $this->input->post('id');
      $this->load->model('Musicmodel');      
      $data2['query2'] = $this->Musicmodel->get($song_id);
      
      $this->load->view('lyrics_view2', $data2);
  }

One more thing. Right now line
Code:
$('a').click(function(){
binds every link on your web page. You should change it to something like
Code:
$('a.ajax_link').click(function(){
and in your view, update all links to lyrics with ajax_link class, for example
Code:
<a name='1' class="ajax_link">Adventures</a>


Messages In This Thread
jquery (ajax) post to controller to model (and back) to view problem - by El Forum - 06-14-2010, 01:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB