Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  170] [ 6]  / answers: 1 / hits: 53853  / 13 Years ago, sun, october 2, 2011, 12:00:00

Quite odd problem, sorry for asking, i'm quite new to Symfony/Twig. My route requires a mandatory region_id paramenter:



ajax_provinces_by_region:
pattern: /ajax/region/{region_id}/provinces
defaults: {_controller: SWAItaliaInCifreBundle:Ajax:provincesByRegion }
requirements: {region_in: d+}


The question is: how can i generate this route based on a select element in javascript (code below)?



The problem is: i can't use path and url helpers from Symfony as they require to specify the region_id parameter (this.value) i can't access because it's a javascript variable (and Twig is compiled server-side).



$(document).ready(function() {
$('select#regions').change(function(){

// Make an ajax call to get all region provinces
$.ajax({
url: // Generate the route using Twig helper
});

});
});

More From » symfony

 Answers
82

You can use the FOSJsRoutingBundle.


[#89829] Thursday, September 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
jenamackennac questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Wed, Apr 21, 21, 00:00, 3 Years ago
Thu, Apr 1, 21, 00:00, 3 Years ago
Tue, Feb 2, 21, 00:00, 3 Years ago
;