Welcome Guest, Not a member yet? Register   Sign In
Passing variables model to javascript
#1

[eluser]RobbieL[/eluser]
I'm currently working on something that pulls a bunch of song information from a database, and displays it on the page. You can then click a link beside each song, and using the Amazon Web Service, grab the album art for that song. It all works great if I manually type the artist and album into the controller. However, I'd like for the artist and album name to be generated dynamically.

The problem is, when the link is clicked to grab the album art, the controller making the call to the Amazon Web Service is called by an ajax function. So I'm having trouble getting the php variables, containing the artist and album name, from the model function into my ajax function so it can then add them as URI segments. Then the controller can grab the URI segments, and fetch the album art.

I'm stumped so far. I tried using PHP to print out a call for the ajax function, putting the PHP variables as parameters, in the view ... but no luck.

Model:
Code:
function get_songs()
{        
    $getSongs = $this->db->query("SELECT title, artist, album FROM tracks WHERE userID='".$_SESSION['username']."'");
        
    $output = '<table><tr>Cover<td></td><td>Title</td><td>Artist</td><td>Album</td></tr>';
        
    if($getSongs->num_rows() > 0)
    {
        foreach($getSongs->result() as $song)
        {
            $artist = $song->artist;
            $album = $song->album;
            
            $output .= '<tr>';
            $output .= '<td>'.$song->cover.'</td>';
            $output .= '<td>'.$song->title.'</td>';
            $output .= '<td>'.$song->playtime.'</td>';
            $output .= '<td>'.$song->artist.'</td>';
            $output .= '<td>'.$song->album.'</td>';
            $output .= '<td>'.$song->genre.'</td>';
            $output .= '<td><a href="[removed]callAmazon('.$artist.', '.$album.');">Album Art</a></td>';
            $output .= '</tr>';
          }
          $output .= '</table>';
          return $output;
      }
      else
      {
          return '<p>You need to add music</p>';
      }
}

Ajax:
Code:
function callAmazon(artist, album)
{    
    new Ajax.Updater('coverContainer', 'http://localhost:8888/honours/index.php/music/amazon/artist/album', {
    method: 'get',
    onLoading: function() {
    $('coverContainer')[removed]='Loading ...';}});
}


Messages In This Thread
Passing variables model to javascript - by El Forum - 01-30-2008, 08:27 AM
Passing variables model to javascript - by El Forum - 01-30-2008, 08:47 AM
Passing variables model to javascript - by El Forum - 01-30-2008, 08:53 AM
Passing variables model to javascript - by El Forum - 01-30-2008, 09:01 AM
Passing variables model to javascript - by El Forum - 01-30-2008, 10:03 AM
Passing variables model to javascript - by El Forum - 01-30-2008, 12:47 PM
Passing variables model to javascript - by El Forum - 01-30-2008, 01:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB