I am trying to send by ajax a property (color) of an entity (product). If I send it this way, it sends me the product id correctly:
public function source(Request $request): Response
{
$producto=$request->request->get('color');
if ($request->isXMLHttpRequest())
{
return new JsonResponse($producto);
}
return new Response('This is not ajax!', 400);
}
but if I try to send the color directly like this:
public function source(Request $request): Response
{
$producto=$request->request->get('color');
if ($request->isXMLHttpRequest())
{
return new JsonResponse($producto->getColor());
}
return new Response('This is not ajax!', 400);
}
It gives me the following error: Call to a member function getColor() on string
in this line of code: return new JsonResponse($producto->getColor());
I've been thinking about it for a day and I don't know why the error could be. By the way, indicate that the color property is a string. All the best.