Diego Bastidas
Diego Bastidas

Reputation: 63

i need pass a variable JavaScript to path method in symfony

I have the next route in Symfony:

 path: /BuscarCriterio/{nombre}

How Can i pass the Variable {nombre} with JavaScript?

var nombre=$('#form_nombre').val();

            var Ruta= "{{ path('BuscarporCriterio',{'nombre':I need my JS Variable Here }) }}";

it is necessary to know i can't use window.location because i need this route for make a call to Ajax.

Thanks for your answer!

Upvotes: 0

Views: 421

Answers (1)

Renan Taranto
Renan Taranto

Reputation: 572

The FOSJsRoutingBundle can be used to generate paths in javascript files https://github.com/FriendsOfSymfony/FOSJsRoutingBundle

Install the bundle and try this inside a js file

var nombre = $('#form_nombre').val();
var Ruta = Routing.generate('BuscarporCriterio', { nombre: nombre });

Upvotes: 1

Related Questions