2
var prova= $("select#utente_regione_name").val();
$.ajax({
    type: "POST",
    url: "{{ path('province', { 'variabile': 'prova<------it's correct?' }) 
}}", 
2
  • 3
    Don't quote the variable name - that makes is a string "prova", not a variable. Commented Jan 30, 2012 at 16:38
  • wuaooo thx very muchhhhh!!!! -.- Commented Jan 30, 2012 at 16:44

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Look at this : FOSJsRoutingBundle. With it you can use router from JS: Routing.generate('my_route_to_expose', { "id": 10, "foo": "bar" });
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.
0

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

i say, can i pass javascript variable to twing?? var "prova" to {{ path('province', { 'variabile': 'prova' } }} it's possible?
0

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" });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.