0
AJAX 성공 후 데이터 테이블을 새로 고치는 방법을 여러 번 시도했지만 행운은 없습니다. 나는 draw()와 .ajax.reload() 함수를 시도했지만 여전히 운이 없다. 그것을 새로 고치는 방법을 알고 있습니까? 여기 아약스 성공 후 어떻게 DataTable을 새로 고칠 수 있습니까?
는HTML 내 코드는 자바 스크립트
<table id="giacenza" class="table table-striped table-bordered">
<thead>
<tr>
<th>Modello</th>
<th>Descrizione</th>
<th>Colore</th>
<th>Taglia</th>
<th>Barcode</th>
<th>Quantità</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
입니다
$(document).ready(function() {
function getRecords(){
$.ajax({
type: "POST",
url: "functions/getImported.php",
success: function(result) {
var table = $('#giacenza').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdfHtml5', 'print'
],
order: [[ 1, "asc" ]],
});
var data = JSON.parse(result);
table.rows.add(data).draw();
},
error: function(result) {
alert("error: "+result);
}
});
}
getRecords();
$("#scarica-articolo").submit(function(event) {
event.preventDefault();
var codbarra = $("#codbarra").val();
$("#scarica-btn").attr("disabled",true);
$.ajax({
type: "POST",
url: "functions/scaricaArticolo.php",
data: {codbarra:codbarra},
success: function(result) {
if(result = "OK"){
new PNotify({
title: 'Articolo scaricato!',
text: 'L\'articolo è già stato scaricato dalla tabella seguente!',
type: 'success',
styling: 'bootstrap3'
});
$("#scarica-btn").attr("disabled",false);
getRecords();
}else if(result == "KO"){
new PNotify({
title: 'Oh No!',
text: 'La query non è andata a buon fine. Contattare l\'assistenza.',
type: 'error',
styling: 'bootstrap3'
});
$("#scarica-btn").attr("disabled",false);
}
},
error: function(result) {
alert("error: "+result);
}
});
});
});
PHP
<?php
include("db_config.php");
$mysqli->set_charset("utf8");
$codbarra = $mysqli->real_escape_string($_POST["codbarra"]);
$query = "UPDATE records SET PARESTALLA = PARESTALLA-1 WHERE CODBARRA = ".$codbarra.";";
$results = array();
$result = $mysqli->prepare($query);
$result->execute();
if($result->affected_rows > 0){
echo "OK";
}else{
echo "KO";
}
?>
편집 : 나는 나의 자바 스크립트 스크립트를 업데이트하지만 난 할 수 내 문제를 해결하지 못합니다.
table.ajax.reload() 함수 나에게이 오류 반환 : "DataTables 경고 : 테이블 ID = giacenza - 잘못된 JSON 응답이 오류에 대한 자세한 내용은 다음을 참조하십시오 HTTP :. /을 /datatables.net/tn/1 " –
해결하려면. 테이블 변수에는 데이터베이스에서 데이터를 가져 오는 Ajax 호출이 있어야합니다. 이것이 Datatable가 다시로드 할 목록을 알고있는 방식입니다. – Akintunde007
업데이트 된 답변 확인 – Akintunde007