I have a problem when i want to delete, it's always still loading and not deleting data. the data that i want to delete already shown, but when i click ok, it won't deleting just loading. is there something wrong ? because create, read and update already success.
table: users
field :
- id
- username
- password
- level
this is the sample of the code :
index.php
function deleteUser(id) {
clearModals();
$.ajax({
type: "POST",
url: "crud.php",
dataType: 'json',
data: { id: id, type: "get" },
success: function (data) {
$("#removeWarning").show();
$("#myModalLabel").html("Delete User");
$("#id").val(data.id);
$("#type").val("delete");
$("#username").val(data.username).attr("disabled", "true");
$("#password").val(data.password).attr("disabled", "true");
$("#level").val(data.level).attr("disabled", "true");
$("#myModals").modal("show");
waitingDialog.hide();
}
});
}
crud.php
case "delete":
$SQL = mysqli_query($con, "DELETE FROM users WHERE username='".$_POST['username']."'");
if($SQL){
echo json_encode("OK");
}
break;
}
server.php
while ( $aRow = $rResult->fetch_assoc() ) {
$row = array();
$btn = '<a href="#" onClick="showModals(\''.$aRow['id'].'\')">Edit</a> |
<a href="#" onClick="deleteUser('.$aRow['id'].')">Delete</a>';
for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
$row[] = $aRow[ $aColumns[$i] ];
}
$row = array( $btn, $aRow['username'], $aRow['password'], $aRow['level'] );
$output['aaData'][] = $row;
}