I'm facing an issue in my Twig view when passing parameters in the AJAX URL path. Since Twig is executed before JavaScript, it doesn't recognize the input value passed as a parameter. Is there a way to solve this without passing the param in data?
<script type="text/javascript" charset="UTF-8">
(function($) {
var $projectField = $('#project-field-container');
$projectField.on('change', function() {
var id_project = $(this).val();
if('' != id_project) {
$.ajax({
url: {{ path('project_field', {'id_project': id_project})}},
success: function (data) {
var content = $('select', data.contentHTML).html();
$projectField.html(content).trigger('change');
}
});
} else {
}
});
})(jQuery);