我正在研究symfony项目(版本3.4),我想从javacsript文件访问路由。我在symfony文档中看到可以使用FOSJsRoutingBundle。我已经按照文档进行了安装和配置,但是当我尝试访问我的网站时,出现此错误:Uncaught SyntaxError:意外的标识符。与这行相关的内容已添加到我的js文件中:
从'../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'导入路由;
这是我在dev.log文件中得到的:
[2018-11-30 22:50:53] request.INFO: Matched route "ens_category_page". {"route":"ens_category_page","route_parameters":{"_controller":"JobeetBundle\\Controller\\CategoryController::indexAction","_route":"ens_category_page"},"request_uri":"http://localhost:8888/jobeet/web/app_dev.php/categories","method":"GET"} []
[2018-11-30 22:50:53] security.INFO:用匿名令牌填充TokenStorage。 [] [] [2018-11-30 22:50:54] doctrine.DEBUG:选择类别t0中的t0.id AS id_1,t0.name AS name_2 [] [] [2018-11-30 22:50:55] request.INFO:匹配的路由“ fos_js_routing_js”。 {“ route”:“ fos_js_routing_js”,“ route_parameters”:{“ _ controller”:“ fos_js_routing.controller:indexAction”,“ _ format”:“ js”,“ _ route”:“ fos_js_routing_js”},“ request_uri”:“ {{ 3}}“,”方法“:” GET“} [] [2018-11-30 22:50:56] request.INFO:匹配的路线“ _wdt”。 {“ route”:“ _ wdt”,“ route_parameters”:{“ _ controller”:“ web_profiler.controller.profiler:toolbarAction”,“令牌”:“ b81260”,“ _ route”:“ _ wdt”},“ request_uri”:“ http://localhost:8888/jobeet/web/app_dev.php/js/routing?callback=fos.Router.setData“,”方法“:” GET“} []
提前感谢您的回复。http://localhost:8888/jobeet/web/app_dev.php/_wdt/b81260
答案 0 :(得分:0)
意外标识符是什么?您复制了完整的错误消息吗?
您可以尝试按照here的说明在布局中加载fos吗,而不是在js文件中导入路由?
<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>