【发布时间】:2023-03-17 10:46:01
【问题描述】:
当我搜索产品时为我显示未定义的 ajax
/**
* @Route("/searchProduit ", name="searchProduit")
*/
public function searchProduit(Request $request,NormalizerInterface $Normalizer)
{
$repository = $this->getDoctrine()->getRepository(Produit::class);
$requestString=$request->get('searchValue');
$products = $repository->findProduitByName($requestString);
$jsonContent = $Normalizer->normalize($products, 'json',['groups'=>'products']);
$retour = json_encode($jsonContent);
return new Response($retour);
}
【问题讨论】:
-
return new JsonResponse($products)这样它会为您编码响应。除此之外,undefined不会来自 Symfony。这听起来更像 Javascript,那么首先调用/searchProduit是什么?
标签: php ajax symfony controller symfony4