[英]Confirm & alert not firing in my Ajax success function
I have a function that displays a table from an Ajax request : 我有一个功能,可以显示来自Ajax请求的表格:
function loadExternalBenefits() {
var id_project = $('input[name=id_project]').val();
$.ajax({
url : '/projects/getExternalBenefits',
method : 'POST',
data : {'fk_project' : id_project, 'ajax' : true},
success : function(result) {
$('#panel-external-benefits').find('.right').first().html(result);
$('.delete_external_benefits').on('click', function() {
if(confirm("Voulez-vous vraiment supprimer cette ligne ?")) {
console.log('ok');
var id_item = $(this).data('id');
deleteExternalBenefits(id_item);
} else {
console.log('ko');
}
return false;
});
},
});
}
If I do a "console.log('something')" in the success function, it works, but I cannot do an alert or a confirm. 如果我在成功函数中执行“ console.log('something')”,则该方法有效,但是我无法发出警报或确认。 Problem is I have a trigger on click that have to fire a confirm window.
问题是单击时有一个触发器,必须触发确认窗口。 It systematicly displays the console.log "ko", without even displaying the dialog.
它系统地显示console.log“ ko”,甚至不显示对话框。
Of course, I have no error in my console and I couldn't find a solution on the Internet because most of the time, it's an issue of Ajax returning an error (not a success). 当然,我的控制台没有错误,并且在Internet上找不到解决方案,因为在大多数情况下,这是Ajax返回错误(不是成功)的问题。
Do you have an idea ? 你有想法吗 ?
@el_tomato : Here is the console.log(result) @el_tomato:这是console.log(结果)
<table class="classic-table">
<thead>
<tr>
<th>Libellé</th>
<th>Quantité</th>
<th>Prix d'achat</th>
<th>Coeff.</th>
<th>Prix total</th>
<th>Marge</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Une prestation externe</td>
<td class="align-center">3</td>
<td class="price align-right">150,00 €</td>
<td class="price align-right">1.2</td>
<td class="price align-right">540,00 €</td>
<td class="price align-right">90,00 €</td>
<td><button class="delete_external_benefits delete" data-id="24">x</button></td>
</tr>
</tbody>
</table>
Put this inside $(document).ready()
, 将其放在
$(document).ready()
,
$(document.body).on("click", ".delete_external_benefits", function(e) {
if(confirm("Voulez-vous vraiment supprimer cette ligne ?")) {
console.log('ok');
var id_item = $(this).data('id');
deleteExternalBenefits(id_item);
} else {
console.log('ko');
}
return false;
});
And in place of the above code, write 并代替上面的代码,写
$('.delete_external_benefits').trigger("click");
I hope that should work 我希望那能奏效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.