title: How can I return a view from an AJAX call in Laravel 5?
body: <p>I'm trying to get an html table to return on an ajax call.  </p>
  
  <p>route:  </p>
  
  <pre><code>Route::post('job/userjobs', 'JobController@userjobs');  
  </code></pre>
  
  <p>ajax on calling page:  </p>
  
  <pre><code>function getUserJobs(userid) {
      $_token = "{{ csrf_token() }}";
      var userid = userid;
      $.ajax({
          headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') },
          url: "{{ url('/job/userjobs') }}",
          type: 'POST',
          cache: false,
          data: { 'userid': userid, '_token': $_token }, //see the $_token
          datatype: 'html',
          beforeSend: function() {
              //something before send
          },
          success: function(data) {
              console.log('success');
              console.log(data);
              //success
              //var data = $.parseJSON(data);
              if(data.success == true) {
                //user_jobs div defined on page
                $('#user_jobs').html(data.html);
              } else {
                $('#user_jobs').html(data.html + '{{ $user-&gt;username }}');
              }
          },
          error: function(xhr,textStatus,thrownError) {
              alert(xhr + "\n" + textStatus + "\n" + thrownError);
          }
      });
  }
  
  
  
  //on page load
  getUserJobs("{{ $user-&gt;id }}");
  </code></pre>
  
  <p>controller:  </p>
  
  <pre><code>public function userjobs() {
      $input = Request::all();
      if(Request::isMethod('post') &amp;&amp; Request::ajax()) {
          if($input['userid']) {
              $userjobs = Userjob::select('select * from user_jobs where user_id = ?', array($input['userid']));
              if(! $userjobs) {
                  return response()-&gt;json( array('success' =&gt; false, 'html'=&gt;'No Jobs assigned to ') );
              }
              $returnHTML = view('job.userjobs')-&gt;with('userjobs', $userjobs);
              return response()-&gt;json( array('success' =&gt; true, 'html'=&gt;$returnHTML) );
  
          }
      }   
  }
  </code></pre>
  
  <p>view:  </p>
  
  <pre><code>@section('content')
  &lt;table class="table table-striped"&gt;
      &lt;tbody&gt;
  @foreach ($userjobs as $userjob)
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;{{ $userjob-&gt;title }}&lt;/strong&gt;&lt;br /&gt;
              {{ $userjob-&gt;description }}
              &lt;/td&gt;
          &lt;/tr&gt;
  @endforeach
  &lt;/table&gt;
  @stop
  </code></pre>
  
  <p>Im not getting anything in the json.html data. nothing. If in the controller I say:  </p>
  
  <pre><code>return response()-&gt;json( array('success' =&gt; true, 'html'=&gt;'&lt;span&gt;html here&lt;/html&gt;') );
  </code></pre>
  
  <p>This works just fine.  </p>
  
  <p>How can I return a view from an ajax call in Laravel 5.</p>