P
P
Prudkovski2014-11-14 22:06:28
JavaScript
Prudkovski, 2014-11-14 22:06:28

Is there another way to insert path parameters from js?

Good afternoon.
The task is the following, you need to pass parameters to path from js.
Now I do this:

function( request, response ) {
    var url = "{{ path('pet_user_profile_search_street', {'place' : 'oggi', 'street': 'cucaracha'}) }}";
    url = url.replace('oggi', $("#addresspicker").val());
    url = url.replace('cucaracha', request.term);
        $.ajax({
            url: url,
            dataType: "json",
            success: function( data ) {
                response( data );
             }
        });
}

Is there a less hacky way?
Thank you!
Or is it better to use url?
var url = "{{url('route_name')}}/"+var_place+"/"+var_street;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2014-11-14
@prudkovski

https://github.com/FriendsOfSymfony/FOSJsRoutingBundle

var url = Routing.generate('my_route_to_expose_with_defaults', { id: 2 });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question