I've created a Ajax request who posts data to a Symfony path. Inside my Symfony path I want to use a Javascript variable to generate my route.
$(document).ready(function () {
function cbOnClick(cb) {
cbValue = cb.checked;
todoId = cb.getAttribute('data-id');
$.ajax({
url: '{{ (path('change_todo_status', {'todo_id': todoId})) }}',
type: "POST",
dataType: "json",
data: {
"status": "cbValue"
},
async: true,
success: function (data) {
console.log(data)
}
});
return false;
}
});
Inside my url I want to set the todoId, but I'm getting te error the variable "todoId" does not exists.