使用jquery数据表,使用ajax获取数据。但它阻止其他jquery像select2不工作和其他jquery onclick删除按钮打开模式删除确认但它也没有打开。我认为它的数据表与ajax阻止其他jquery,因为相同使用没有ajax它工作正常。
ajax代码:
$.ajax({
type: "post",
url: "ajax.php",
dataType: 'json',
data:'act=GetAllProduct' ,
success: function(data){
var trHTML = '';
var j = 1;
$.each(data, function (i) {
if(data[i]["Enable"] == 1){
Enable = "Active";
}else{
Enable = "Deactive";
}
Action = '<a href="add.product.php?mode=edit&productid='+ data[i]["ProductID"]+'" class="btn btn-primary btn-mini"> <i class="icon-edit"></i> Edit Product </a> '+
'<a href="add.product.image.php?mode=edit&productid='+ data[i]["ProductID"]+'" class="btn btn-primary btn-mini " ><i class="icon-picture"></i> Add Images </a> ' +
'<a href="#" data-toggle="modal" class="btn btn-danger btn-mini btnDelete " > <i class="icon-trash"></i> Delete </a>' ;
trHTML += '<tr><td>' + j + '</td><td>' +
data[i]["BarCode"] + '</td><td>' +
data[i]["ProductName"] + '</td><td>' +
data[i]["Ref"]+ '</td><td>' +
data[i]["CatName"] + '</td><td>' +
data[i]["BrandName"]+ '</td><td>' +
Enable + '</td><td>' +
data[i]["Featured"] + '</td><td>' +
Action+ '</td></tr>';
j++;
});
$('.data-table > tbody').html(trHTML);
$('.data-table').DataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<""lf>t<"F"ip>',
aLengthMenu: [
[10, 25, 50, 100, 200, 500],
[10, 25, 50, 100, 200, 500]
]
});
}
});
$('select').select2();
$('a.btnDelete').on('click', function (e) {
e.preventDefault();
var id = $(this).closest('tr').data('id');
var tbl = $(this).closest('tr').data('tbl');
var idval = $(this).closest('tr').data('idval');
var col = $(this).closest('tr').data('col');
var ttl = $(this).closest('tr').data('ttl');
$('#myAlert').data({'id':id, 'tbl': tbl, 'idval' : idval, 'col' : col, 'ttl' : ttl} ).modal('show');
});