How to show network error in DATATABLE Ajax Call
How to show network error in DATATABLE Ajax Call
SalmanS
Posts: 102Questions: 12Answers: 0
Hi Everyone,
My server side script works fine, however when the server or network is down, i would like to show error message.
I am aware in my javascript, there is an issue with date field, where it not converting empty values, convert empty column to something meaningful but now it just showing Null.
ie., success or error
Here is my ajax call code?
`$(document).ready(function(){
$('#empTable').DataTable({
'processing': true,
'serverSide': true,
'serverMethod': 'post',
'ajax': {
'url':'ajaxfile.php'
},
cache: false,
'columns': [
{ data: 'emp_no' },
{ data: 'first_name' },
{ data: 'last_name' },
{ data: 'gender' },
{ data: 'hire_date',
"render": function (data) {
var dateObj = new Date(data);
var month = ('0' + (dateObj.getMonth() + 1)).slice(-2);
var date = ('0' + dateObj.getDate()).slice(-2);
var year = dateObj.getFullYear();
//var shortDate = year + '/' + month + '/' + date;
return (date + '/' + month + '/' + year);
}
},
],
rowReorder: {
dataSrc: 'id'
}
});
});`
Any help is highly appreciated.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can use the jQuery
error
function for this. Just add it to theajax
option config. Theajax
docs discuss what happens when passing the option as an object. Make sure not to use the ajaxsuccess
function.Are you asking for debugging help with this or how to return something other than
null
?If debugging then please provide a test case replicating the issue. Otherwise in your render function you will need to check for
null
value and if it is then return the desired output. Otherwise return the computed date.Kevin
I am little confused as to how i would be using jquery error function for this? having a look at the docs its unclear.
I tried to modify the ajax call as follows: but get no results.
There should be a comma, not a period, between the
}
anderror
.Here is an example with an incorrect
url
.http://live.datatables.net/zivoqozi/1/edit
Kevin
Thanks, I done that as follows and it worked.
I had to figure out how to append this values in the datatable table instead of processing .... message in the window...when the network is down or any issues.
This is the best forum in the world, specially kevin and colin - they dont have to answer our queries, but they are always there, even for silly questions related or unrelated to datatables. this is the prime example of sincere and honest people in the world.
One simple sentence
World class free support.