title: Twitter like follow system with CodeIgniter and Ajax
body: <p>I'm currently programming a subscribers / followers system like on twitter and facebook with CodeIgniter.</p>
  
  <p>So, the idea is to create a link on he users' profil page and give the opportunity to the users to follow artist or promotor on the website and see the news and feeds of them.</p>
  
  <p>Basically this is the same idea has twitter.</p>
  
  <p>How can we create a think like that with just a link.</p>
  
  <p>For the moment, I have a database with the id of the follower, the id of the artist.
  If one user want to follow an other, he click on the link and one row is add in the database with this two values, if he click one more time, the row is deleted from the database and the users in 'unfollow'</p>
  
  <p>I create an anchor link like this:</p>
  
  <p><code>
  anchor('follow','Follow',array('id'=>'follow','data-id' => '2'));</code></p>
  
  <p>wich mean on my screen, I have
  <code></p>
  
  <p>a href="http://localhost:8888/sanyproject/follow" id="follow" data-id="2"
  </code></p>
  
  <p>For the ajax part I have create this:</p>
  
  <p><code>
  $(document).ready(function(){</p>
  
  <pre><code>$('#follow').click(function(e){
      e.preventDefault();
      $.ajax({
        url: "profile/follow",
        data: { id : $('#follow').attr('data-id')}
      }).done(function( msg ) {
        alert( "Data: " + msg );
      }).error(function( msg ) {
        alert( "Data Saved: " + msg );
      });
  });
  </code></pre>
  
  <p>});
  </code></p>
  
  <p>So, now the idea is to send to my controller profile/follow the id of the artist and insert or delete the value in my database.</p>
  
  <p>I really, really don't know how to do it, this is my first app on CodeIgniter, so I take all constructed advice!</p>