FOSJsRouting 捆绑包 "The route does not exist"

FOSJsRouting Bundle "The route does not exist"

我正在尝试为我的 file.js 中的 Ajax 呼叫生成路由。我已经安装了 FOSJsRoutingBundle 并按照说明进行操作。我为请求公开了我的路由,但是 Routing.generate() 方法给出了错误 The route 'ajax' does not exist。我用按钮测试了路线,它有效。

Javascript 文件

$('#add_assistant_next').click(function () {
        var route = Routing.generate('ajax');
       var that = $(this);
       var i = $.ajax({
           url: route,
           type: "POST",
           dataType: "json",
           data: {"ajax-user": "test user string"},
           async: true,
           success: function (data) {
               $('div#ajax-results').html(data.output);
           }
       });
        return false;
    });

控制器路由

/**
     * @Route(name="ajax", options={"expose" = true}, 
     *         methods={"GET", "POST"}, 
     *          path="/ajax")
     *
     *
     *
     */
    public function ajaxAction(Request $request)
    {
        dump('route called');
        die();
        if ($request->request->get('ajax-user')) {
            dump('request recieved');
            die();
        }

    }

每次添加新路线时都需要转储路线 https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html