return response()->json to Laravel View - AJAX
<p>How do you access JSON within your Laravel 5.2 blade view after an AJAX post request? It seems as though my variable </p>

<blockquote>
  <p>{{ $trackedAddress }}</p>
</blockquote>

<p>is not accessible within the view since it will error saying that it is undefined. However, within my console I can see that the JSON object exists after the click event.</p>

<p><strong>Controller:</strong></p>

<pre><code>public function postModalChart(Request $request)
{
  $task_address = $request['taskAddress'];
  $task_city = $request['taskCity'];

  $user = Auth::user();
  $userId = $user-&gt;id;

  $trackedAddress = DB::table('tasks')
      -&gt;join('soldhomestest', function ($join) {
          $join-&gt;on('tasks.address', '=', 'soldhomestest.address')
              -&gt;on('tasks.city','=','soldhomestest.city');
        })
      -&gt;where([
            ['user_id', '=', $userId],
            ['tasks.address', '=', $task_address],
            ['tasks.city', '=', $task_city],
        ])
      -&gt;get();

  return response()-&gt;json($trackedAddress);
}
</code></pre>

<p><strong>JQuery:</strong></p>

<pre><code>$('.trackedAddress').on('click', function(event) {
    event.preventDefault();
    var self = $(this),
    taskAddress = self.data('address');
    taskCity = self.data('city');
    var target = self.data('target');
    $.ajax({
        method: 'POST',
        url: 'postModalChart',
        dataType: 'json',
        data: {taskAddress: taskAddress, taskCity: taskCity, _token: token},
    })
    .done(function(data) {
        console.log(data);
        $('#'+target).val(data);
    });
});
</code></pre>