Reputation: 63
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
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