var prova= $("select#utente_regione_name").val();
$.ajax({
type: "POST",
url: "{{ path('province', { 'variabile': 'prova<------it's correct?' })
}}",
-
3Don't quote the variable name - that makes is a string "prova", not a variable.Diodeus - James MacFarlane– Diodeus - James MacFarlane2012-01-30 16:38:42 +00:00Commented Jan 30, 2012 at 16:38
-
wuaooo thx very muchhhhh!!!! -.-Popolitus– Popolitus2012-01-30 16:44:44 +00:00Commented Jan 30, 2012 at 16:44
Add a comment
|
3 Answers
You 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.
2 Comments
Miles M.
Look at this : FOSJsRoutingBundle. With it you can use router from JS: Routing.generate('my_route_to_expose', { "id": 10, "foo": "bar" });
matt_jay
I had the same problem and got this to work in a snap with the FOSJsRoutingBundle. @MilesM.: would you also post this a an answer, as it appears to be the most convenient way of solving this type of challenge.
You can't access data which comes in array $_POST in twig. You should change you script to pass variable from $_POST to you twig template.
1 Comment
Popolitus
i say, can i pass javascript variable to twing?? var "prova" to {{ path('province', { 'variabile': 'prova' } }} it's possible?