Accepted answer

Install FOSJsRoutingBundle, create a correct route as it is incorrect in your question.

So, you should do something like this:

add bundle JS (may be in base template for global usage):

<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>

configure routing (without QS):

    path:     /autocomplete
        _controller: CatalogWebBundle:Default:autocomple
        expose: true

configure your JS:

<script type="text/javascript">
    $(function() {

            source: Routing.generate('autocomplete', { 'term': value });,
            minLength: 1



besides the above version (using FOS JS Routing), if you are "rendering" the JS function files without any need for "dynamic generation or routes" you can use a more simple approach

{{ path('routeName', {'slug': slug}) }}

Note: in your case - building a search - it won't work

Related Query

More Query from same tag