title: Passing data from view to controller using ajax
body: <p>I am trying to send some data on button click to a controller and display the response in a content div back in the view. However i am facing problem while sending the data to the controller. Here is what i am trying to do : </p>
  
  <p><strong>test.php</strong>
      </p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      $("#btn1").click(function(){
          $.ajax({
              type: 'GET',
              url: 'get-response',
              dataType: 'json',
              data: {
                  "id": "1"
              },
              success: function(response){
  
                  $('#content').html(response.first);
              }
          });
  
      });
  
       $("#btn2").click(function(event){
          $.ajax({
              type: 'GET',
              url: 'get-response',
              dataType: 'json',
              data: {
                  "id": "2"
              },
              success: function(response){
  
                  $('#content').html(response.first);
              }
          });
  
      });
      });
      &lt;/script&gt;
  
  
     &lt;input type="button" id="btn1" value="Button1 Content" /&gt;
     &lt;input type="button" id="btn2" value="Button2 Content" /&gt;
     &lt;br&gt;
     &lt;div id="content"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>route.php</strong></p>
  
  <pre><code>Route::get('ajax-example', function(){
  return View::make('test');
  });
  
  Route::get('get-response/{id}', array('as'=&gt;'get-response', 'uses'=&gt;'AjaxController@getResult'));
  </code></pre>
  
  <p><strong>AjaxController.php</strong></p>
  
  <pre><code>public function getResult($id){
      if($id==1){
          $content = "Hello";
  
      }
      else if($id==2){
          $content = "World";
  
      }
      return Response::json(array('first'=&gt;$content));
  }
  </code></pre>
  
  <p><strong>Error</strong>
  <img src="https://i.stack.imgur.com/cmgml.png" alt="enter image description here">
  Can anyone please help me out here. I am a bit confused right now. Thanks :)</p>