ServerSide Custom Error Messages
ServerSide Custom Error Messages
Hi , I'm new to datatables and implemented server-side processing for my site with Datatables.
It works great, does sorting/filtering/pagination on the server side really well, thanks to the great example documentation.
However, I would just like to over-ride the error message that shows up for unsuccessful Ajax calls, such as when the server is down. I've been playing around with fnServerData and have been trying to find an example of how to do this. I was able to override the error message function, but I lose all the pagination/filter/sort information that is sent:
[code]
var tableParameters = {
...,
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback,
"error": function () {
alert( "My custom error message." );
}
} );
}
}
$('#my_table').dataTable(tableParameters);
[/code]
How can I override the error function for the ajax call but still retain all the pagination/sort/filter variables that are sent in the GET request?
Thanks!
Lee
It works great, does sorting/filtering/pagination on the server side really well, thanks to the great example documentation.
However, I would just like to over-ride the error message that shows up for unsuccessful Ajax calls, such as when the server is down. I've been playing around with fnServerData and have been trying to find an example of how to do this. I was able to override the error message function, but I lose all the pagination/filter/sort information that is sent:
[code]
var tableParameters = {
...,
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback,
"error": function () {
alert( "My custom error message." );
}
} );
}
}
$('#my_table').dataTable(tableParameters);
[/code]
How can I override the error function for the ajax call but still retain all the pagination/sort/filter variables that are sent in the GET request?
Thanks!
Lee
This discussion has been closed.
Replies
I had to override the fnServerData function in the settings object, and not pass it in as an initialization parameter:
[code]
oSettings = $('#my_table').dataTable(tableParameters).fnSettings();
oSettings.fnServerData = function ( url, data, callback ) {
$.ajax({
"url": url,
"data": data,
"success": callback,
"dataType": "json",
"cache": false,
"error": function () {
alert("Booyah!");
}
});
};
[/code]
Thanks anyways, hopefully this'll help someone else out.
Any chance you can post an example of the page which isn't working? Although, you've got it working now - nice one :-)
Allan
My server is expecting a GET and not a POST, and I had it configured on Datatables to POST.
I configured the fnServerData like in the example, and it worked when I use the correct type.
Probably can delete this thread since it's pretty useless now :-)
Allan