0

i wanna pass a json result parameter to a twig format in file "A.js.twig" as follow:

$.ajax({
          type: 'POST',
          url: "managemore",
          success: function(msg){

            var ret = $.parseJSON(msg)
            var str = '';
             for (var i=0; i<ret.deliverLength; i++)
             {
                str = str + "<a href=\" {{ path('changeJob', {'jid':ret.deliver[i]['jid']}) }} \", target=\"_self\" ><li>hello</li></a>";
             }

           },
           error: function(XmlHttpRequest,textStatus, errorThrown){
                 alert("fail");
            }
});

it went wrong...so how can i pass the ret.deliver[i]["jid"] in the twig format in the right way? Thanks a lot.

3
  • try github.com/FriendsOfSymfony/FOSJsRoutingBundle Commented Mar 3, 2014 at 12:37
  • i have used the FOSJsRoutingBundle..but i dont know how to pass the parameter.i tried,but fail. Commented Mar 3, 2014 at 12:56
  • it cant understand what's the value of js parameter"ret.deliver[i]['jid'] " in twig in the example Commented Mar 3, 2014 at 12:59

1 Answer 1

2

Check documentation for FOSJsRoutingBundle : https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/index.md

To generate route using this bundle use one of example statements:

Routing.generate('my_route_to_expose', { id: 10 });
// will result in /foo/10/bar

Routing.generate('my_route_to_expose', { id: 10, foo: "bar" });
// will result in /foo/10/bar?foo=bar

$.get(Routing.generate('my_route_to_expose', { id: 10, foo: "bar" }));
// will call /foo/10/bar?foo=bar

Routing.generate('my_route_to_expose_with_defaults');
// will result in /blog/1

Routing.generate('my_route_to_expose_with_defaults', { id: 2 });
// will result in /blog/2

Routing.generate('my_route_to_expose_with_defaults', { foo: "bar" });
// will result in /blog/1?foo=bar

Routing.generate('my_route_to_expose_with_defaults', { id: 2, foo: "bar" });
// will result in /blog/2?foo=bar

For your problem it will looks smt like this:

str = str + Routing.generate('changeJob', { jid: ret.deliver[i]['jid']}) + <li>hello</li>   </a>";
Sign up to request clarification or add additional context in comments.

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.