I'm work with symfony for an E-commerce project. I have like to display a pop-up window in relation to each product. this pop-up window have a list choices. so for that I like to pass the controller for this window by Ajax to be dynamic , for that :
Code HTML
{% for p in products %}
<a id="#basket-modal" href="#" data-id="{{ p.id }}" data-toggle="modal" data-target="{{ modal }}" class="btn btn-primary">
{% endfor %}
Script
<script type="text/javascript">
$(document).ready(function(){
$("#basket-modal").on({ click: function() {
var op_prod_id = $(this).data('id');
$.ajax({
url: "{{ path('ajout_prod_panier', {'id': op_prod_id }) }}" ,
type: "POST",
data: "op_prod_id="+op_prod_id,
success: function(data, status, xhr) {
console.log(data);
},
error: function(jqxhr, status, error) {
console.log(error);
}
});
event.stopPropagation();
}
});
});
</script>
the problem that always I have an error message :
Variable "op_prod_id" does not exist.
in url:
"{{ path('ajout_prod_panier', {'id': op_prod_id }) }}"