Reputation: 83
I need to pass the var 'busqueda' for the path, if instead of using the var I put text if it works, but to shove the variable tells me there.
JavaScript code in twig.
var busqueda = document.getElementById('search_keywords').value;
xmlhttp.open("GET","{{path('searchCorreos', {'page': thisPage, 'search': busqueda } )}}",true);
xmlhttp.send();
Upvotes: 1
Views: 483
Reputation: 881
If you run into this problem more often (needing to append javascript variables to symfony generated paths/urls) you can make use of the FOSJsRoutingBundle: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
This allows you to do the following in your javascript source:
var busqueda = document.getElementById('search_keywords').value;
var path = Routing.generate('searchCorreos', { page: 'thisPage', search: busqueda });
xmlhttp.open("GET", path, true);
xmlhttp.send();
Upvotes: 0
Reputation: 1884
Since it's a GET request, this should work:
var busqueda = document.getElementById('search_keywords').value;
xmlhttp.open("GET","{{ path('searchCorreos', {'page': thisPage}) }}&search=" + busqueda,true);
xmlhttp.send();
Upvotes: 1