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.
我需要传递var'busqueda'作为路径,如果不是使用var我放置文本,如果它工作,但推动变量告诉我那里。
JavaScript code in twig.
树枝中的JavaScript代码。
var busqueda = document.getElementById('search_keywords').value;
xmlhttp.open("GET","{{path('searchCorreos', {'page': thisPage, 'search': busqueda } )}}",true);
xmlhttp.send();
2 个解决方案
#1
0
Since it's a GET request, this should work:
由于这是一个GET请求,这应该工作:
var busqueda = document.getElementById('search_keywords').value;
xmlhttp.open("GET","{{ path('searchCorreos', {'page': thisPage}) }}&search=" + busqueda,true);
xmlhttp.send();
#2
0
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
如果你经常遇到这个问题(需要将javascript变量附加到symfony生成的路径/ url),你可以使用FOSJsRoutingBundle:https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
This allows you to do the following in your javascript source:
这允许您在javascript源代码中执行以下操作:
var busqueda = document.getElementById('search_keywords').value;
var path = Routing.generate('searchCorreos', { page: 'thisPage', search: busqueda });
xmlhttp.open("GET", path, true);
xmlhttp.send();
#1
0
Since it's a GET request, this should work:
由于这是一个GET请求,这应该工作:
var busqueda = document.getElementById('search_keywords').value;
xmlhttp.open("GET","{{ path('searchCorreos', {'page': thisPage}) }}&search=" + busqueda,true);
xmlhttp.send();
#2
0
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
如果你经常遇到这个问题(需要将javascript变量附加到symfony生成的路径/ url),你可以使用FOSJsRoutingBundle:https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
This allows you to do the following in your javascript source:
这允许您在javascript源代码中执行以下操作:
var busqueda = document.getElementById('search_keywords').value;
var path = Routing.generate('searchCorreos', { page: 'thisPage', search: busqueda });
xmlhttp.open("GET", path, true);
xmlhttp.send();