title: Return a view via ajax in laravel
body: <p>I want to display a view to the user whenever user clicks on a button using ajax.<br>
  This is my code.</p>
  
  <pre><code>// BASE = localhost/project/public/
  
      $('#button').click(function() {
          $.ajax({
              url: BASE + "user/settings",
              type: 'GET'
          })
          .done(function( data ) {
              console.log( data );
          });
      });  
  </code></pre>
  
  <p>And my routes.php</p>
  
  <pre><code>Route::get('user/settings', 'UserController@getSettings');
  </code></pre>
  
  <p>And UserController.php</p>
  
  <pre><code>public function getSettings(){
      return View::make('user.settings');
  }
  </code></pre>
  
  <p>But output is this error: </p>
  
  <pre><code>{"error":{"type":"ErrorException","message":"Undefined offset: 0","file":"H:\\dev    \\xampp\\htdocs\\lchat\\vendor\\laravel\\framework\\src\\Illuminate\\Support    \\Collection.php","line":470}}
  </code></pre>
  
  <p>EDIT: error was in view. I fixed it.</p>
  
  <p>Problem2: The page which is loading via ajax, itself contains another ajax post request. but it's not sending data via ajax anymore. refreshes the page to send data.  </p>
  
  <p>The jquery code:</p>
  
  <pre><code>$('#settings :submit').click(function(e){
      e.preventDefault();
      $.post(BASE +  'settings/save', {
          'userName' : $('#userName').val()
          }, function(data) {
              return 'OK';
      });
  });
  </code></pre>
  
  <p>Problem solved: I used <code>.on</code> to bind event:</p>
  
  <pre><code>$(document).on('click', '#settings :submit', function(e){ ... } );
  </code></pre>
  
  <p>It's working...
  Thank everyone.</p>