Ajax request failed while working :|
Ajax request failed while working :|
Link to test case:
Debugger code (https://debug.datatables.net/ozitew)**: https://debug.datatables.net/ozitew - broken version
**Debugger code (https://debug.datatables.net/epatuy)**: https://debug.datatables.net/epatuy - working version
**Error messages shown: DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7
Description of problem: I have no idea why this doesn't work now, but it used to work before i decided to clean up my server files and redistribute them. It probably is something really stupid but for the sake of me i can't find my fault, if someone can spot it i would be grateful
Ajax request
$(document).ready(function() {
var table = $('#example').DataTable({
"ajax": "scripts/datatables.php",
"processing": true,
"serverSide": true,
"order": [
[1, "desc"]
],
//"responsive": true,
"columns": [{
"data": "Name",
},
{
"data": "Date",
},
{
"data": "Comments",
},
{
"data": "Actions",
"render": function(data, type, full, row) {
return '<a class="Edit btn btn-secondary btn-app"><i style="color: Black;" class="fas fa-edit"></i>Edit</a><a class="Apply btn btn-warning btn-app"><i style="color: Green;" class="fas fa-check-square"></i>Apply</a><a class="Download btn btn-primary btn-app"><i style="color: Blue;" class="fas fa-download"></i>Download</a><a class="Delete btn btn-danger btn-app"><i style="color: Red;" class="fas fa-minus-square"></i>Delete</a>';
},
},
],
dom: '<f<t><l><ip>>',
});
$('#example tbody').on('click', '.Apply', function() {
var row = $(this).closest('tr');
var data = table.row(row).data().Actions;
console.log(data);
});
$('#example tbody').on('click', '.Download', function() {
var row = $(this).closest('tr');
var data = table.row(row).data().Actions;
Name = table.row(row).data().Name;
//console.log(data);
var a = document.createElement('a');
a.setAttribute('download', Name + '.json');
a.setAttribute("href", data);
document.body.appendChild(a);
a.click();
});
$('#example tbody').on('click', '.Edit', function() {
var row = $(this).closest('tr');
var data = table.row(row).data().Actions;
var url = data;
Name = table.row(row).data().Name;
document.getElementById('config-editor').hidden = false;
localStorage.setItem('Data', data);
//console.log(data);
$.ajax({
'async': false,
'global': false,
'url': url,
'dataType': "json",
'success': function(data) {
json = data;
}
});
//console.log(json);
editor.expandAll();
editor.set(json);
editor.refresh();
editor.focus();
});
$('#example tbody').on('click', '.Delete', function() {
var row = $(this).closest('tr');
var data = table.row(row).data().Actions;
//console.log(data);
$.ajax({
method: "POST",
url: "scripts/deletefromdb.php",
data: {
text: data
}
})
.done(function(response) {
//alert(response);
});
$('#example').DataTable().ajax.reload();
// eventFire(document.getElementById('datatables'), 'click');
});
});
PHP file
// DB table to use
$table = 'ConfigFiles';
// Table's primary key
$primaryKey = 'ID';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'Name', 'dt' => "Name" ),
array( 'db' => 'Date', 'dt' => "Date" ),
array( 'db' => 'Comments', 'dt' => "Comments"),
array( 'db' => 'Actions', 'dt' => "Actions" ),
);
$sql_details = array(
'user' => 'myuser',
'pass' => 'mypass',
'db' => 'mydb',
'host' => 'myhost'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( 'ssp.class.php' );
// Validate the JSONP to make use it is an okay Javascript function to execute
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
HTML
<table id="example" class="table table-striped table-bordered table-hover" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Date</th>
<th>Comments</th>
<th>Actions</th>
</tr>
</thead>
</table>
This question has an accepted answers - jump to answer
Answers
Follow the steps provided in the link:
http://datatables.net/tn/7
The error is due to something on the server. You will need to look at your server logs to troubleshoot the problem.
Kevin
THANKS for the pointers
I hadn;t upload the new ssp.class.php to the new dirs