Php 未定义的数据结果ajax symfony
搜索产品时为我显示的ajax未定义Php 未定义的数据结果ajax symfony,php,ajax,symfony,controller,symfony4,Php,Ajax,Symfony,Controller,Symfony4,搜索产品时为我显示的ajax未定义 /** * @Route("/searchProduit ", name="searchProduit") */ public function searchProduit(Request $request,NormalizerInterface $Normalizer) { $repository = $this->getDoctrine()->getRepository(Produit::c
/**
* @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);
}
首先检查,如果您的
$products
返回任何内容,例如转储:转储($products)代码>
如果是,请尝试返回JsonResponse
use Symfony\Component\HttpFoundation\JsonResponse;
// encode your $products on the fly
$response = new JsonResponse($products);
// if the data to send is already encoded in JSON
$response = JsonResponse::fromJsonString('$jsonContent');
返回新的JsonResponse($products)
这样它就为您编码了响应。除此之外,未定义的
不会来自Symfony。这听起来更像是Javascript,那么首先调用/searchProduit
是什么呢?