我在后端使用Symfony(我在数据库中返回数据invoque时创建控制器)..现在使用Ajax我在控制器中有invoqu数据返回但是我有这个错误:
[![enter image description here][1]][1]
代码控制器:
<?php
namespace Tag\TagBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class TagController extends Controller
{
/**
*@ param Request $request
*/
public function indexAction(Request $request) {
$em = $this->getDoctrine()->getManager();
$rep = $em->getRepository('TagBundle:Tag')->findAll();
return $this->json($rep,200,[],['groups' => ['public']]);
}
}
代码JS:
$( function() {
$.ajax({
url:Routing.generate('tags'),
type:'post',
cache:false,
success: function(data,response){
var data = JSON.parse('data');
console.log(data);
$( ".bootstrap-tagsinput > input" ).autocomplete({
source: data
});
}
});
} );