jquery - return response()->json to Laravel View - AJAX -


how access json within laravel 5.2 blade view after ajax post request? seems though variable

{{ $trackedaddress }}

is not accessible within view since error saying undefined. however, within console can see json object exists after click event.

controller:

public function postmodalchart(request $request) {   $task_address = $request['taskaddress'];   $task_city = $request['taskcity'];    $user = auth::user();   $userid = $user->id;    $trackedaddress = db::table('tasks')       ->join('soldhomestest', function ($join) {           $join->on('tasks.address', '=', 'soldhomestest.address')               ->on('tasks.city','=','soldhomestest.city');         })       ->where([             ['user_id', '=', $userid],             ['tasks.address', '=', $task_address],             ['tasks.city', '=', $task_city],         ])       ->get();    return response()->json($trackedaddress); } 

jquery:

$('.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);     }); }); 

php (and laravel blade template) cant access variables added browser page after page loaded, because php dont work way ... dead till make next request either loading new page, or sending ajax request.

if want make real time changes on page, have stick ajax (if need php interaction) or javascript/jquery.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -