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
});
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…