我有一個問題,當我想在模板Twig中使用Ajax和Symfony刪除註冊表時。Symfony刪除ajax
<tbody>
{% for entity in entities %}
<tr>
<td>
<a class="delete btn btn-danger btn-xs glyphicon glyphicon-trash" data-playgroup-id="{{ entity.id }}" ></a>
</td>
</tr>
{% endfor %}
</tbody>
阿賈克斯:
$(document).ready(function() {
$(".delete").click(function(){
var pid = $(this).attr("data-playgroup-id");
bootbox.confirm("Are you sure?", function(result) {
if(result){
$.ajax({
url: '{{path('playergroup_delete', { 'id': pid}) }}',
type: 'delete',
success: function(result) {
console.log('Delete');
},
error: function(e){
console.log(e.responseText);
}
});
}
});
});
});
我收到一個錯誤:
變量 「PID」 並不存在。
謝謝!
你的url屬性看起來很時髦。檢查引號和輸出結果應該是什麼......''var url =「{{path('playergroup_delete',{'id':」+ pid +「})}}」' –
@PhilCooper它沒有,它是小枝語法 – Jean
@jean我站在更正! –