admin管理员组文章数量:1388903
var prova= $("select#utente_regione_name").val();
$.ajax({
type: "POST",
url: "{{ path('province', { 'variabile': 'prova<------it's correct?' })
}}",
var prova= $("select#utente_regione_name").val();
$.ajax({
type: "POST",
url: "{{ path('province', { 'variabile': 'prova<------it's correct?' })
}}",
Share
Improve this question
edited Jul 15, 2012 at 10:41
hakre
198k55 gold badges449 silver badges856 bronze badges
asked Jan 30, 2012 at 16:33
PopolitusPopolitus
4631 gold badge8 silver badges21 bronze badges
2
- 3 Don't quote the variable name - that makes is a string "prova", not a variable. – Diodeus - James MacFarlane Commented Jan 30, 2012 at 16:38
- wuaooo thx very muchhhhh!!!! -.- – Popolitus Commented Jan 30, 2012 at 16:44
3 Answers
Reset to default 4You can pass it as an attribute, like this:
var prova= $("select#utente_regione_name").val();
$.ajax({
type: "POST",
url: "{{ path('province') }}",
data: { variable: prova },
}}",
of course that means that in Controller you should read it from
$variable = $this->getRequest()->get('variable');
and remove that from your route. I don't think it's so crucial to have that parameter in route for Ajax routes.
PS. I would appreciate if somebody will post how to do this in a true Symfony way, because this still looks like workaround for me.
You can't access data which es in array $_POST
in twig. You should change you script to pass variable from $_POST
to you twig template.
Using FOSJsRoutingBundle will do the job fine. - that's precisely why it has been made for.
With it you can use router from JS:
Routing.generate('my_route_to_expose', { "id": 10, "foo": "bar" });
本文标签: phphow can pass javascript variable to twigStack Overflow
版权声明:本文标题:php - how can pass javascript variable to twig? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744575981a2613627.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论