title: Calling a controller function in javascript that will store an entry in a database using ajax (Laravel 4)
body: <p>I am trying to store an entry in a database after a click using an ajax call to a route that calls a controller function in javascript (in Laravel 4).  </p>
  
  <p>I have a resource "artists", that is controlled by an "ArtistsController".  The view where I am making the call is called "show.blade.php" in an "artists" directory (i.e. the page shows different artists: artists/1, artists/2, etc...).  </p>
  
  <p>I also have a table called "fanartists", where I want to store this data.  Basically, when a user clicks a button on a specific artist's page, I want the relationship to be stored in this table.  </p>
  
  <p>Here is the relevant code:</p>
  
  <p>show.blade.php:</p>
  
  <pre><code>&lt;script&gt;
  window.fbAsyncInit = function() {
      FB.init({
          appId      : '*****************',
              status     : true,
              cookie     : true,
              oauth      : true
              //xfbml      : true  
      });
  
  
        $( '.opener' ).click(function() {
          FB.ui({
              method: 'feed',
  
              link: 'http://crowdtest.dev:8888/artists/',
              name: 'Hello',
              caption: 'Hello',
              description: 'Hello!'
  
              });
  
              request = $.ajax({
          url: "/artists/fbclick",
          type: "post",
          data: serialised data
       });
  
        });
  };
  &lt;/script&gt;
  
  &lt;a class="add-list-button-no-margin opener" style="color: white; font:14px / 14px 'DINMedium','Helvetica Neue',Helvetica,Arial,sans-serif;"&gt;Play my city&lt;/a&gt;
  </code></pre>
  
  <p>ArtistsController:</p>
  
  <pre><code>public function fbclick($id) {
  
          $artist = Artist::find($id);
  
          $fanartist = new Fanartist;
          $fanartist-&gt;artist_id = $artist-&gt;id; //the id of the current artist page (i.e. artists/1, id=1)
          $fanartist-&gt;fan_id = Auth::user()-&gt;id;
          $fanartist-&gt;save();
  
      }
  </code></pre>
  
  <p>routes:</p>
  
  <pre><code>Route::get('/artists/fbclick', array('uses' =&gt; 'ArtistsController@fbclick'));
  </code></pre>
  
  <p>When I include the ajax request, the FB feed does not pop up.  When I remove it, it does.  Also, it is not storing the data in the database like I want it to.  </p>
  
  <p>Do you see anything wrong here?  Your help is much appreciated.  Thank you.    </p>