[ad_1]
View
$.ajax({
type: 'GET',
url: '/company/ajaxGetClients/1',
dataType: 'json',
success: function(response) {
console.log(response); // Expecting this response logged in console.
},
error: function (a, e){
console.log(e); // This logs "parseerror".
}
})
CompanyController
public function ajaxGetClients($id)
{
return response(Company::findOrFail($id)->clients->toArray()); // versions without toArray() or with toJson() also does not work. response()->json() same result.
}
Response
[{"id":1,"name":"John","company_id":1,"phone":null,"email":null,"created_at":null,"updated_at":null}
As you can see, response is missing ending bracket ]
making json invalid and ajax fails to parse it. Is it a bug in Laravel 9.15 or am I doing something wrong?
[ad_2]