So I've been struggling with this problem for the past few days. I want to return $name as a json response but when I try to access it in the success function it doesn't give me the wanted result but it gives me undefined.
The Controller code
$name = Auth::user()->first_name.Auth::user()->last_name.Auth::user()->id.'.jpg';
return response()->json(['name' => $name]);
The AJAX code
success: function (data){
console.log(data.name);
}
Can you make a screenshot? I don't understand if the payload is an object or a "result".
it's pretty basic
$.ajax({
dataType: 'json',
url: "{{ url('/') }}",
data: {
_token: $('input[name=_token]').val()
},
success: function (data){
console.log(data);
},
)};
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community