"Processing" notice and AJAX error handling
"Processing" notice and AJAX error handling
DaveBurns
Posts: 17Questions: 0Answers: 0
If the Ajax call to get data from the server fails and bProcessing is set to true, the box with "Processing..." remains. Is this expected behavior? Is there an official way to dismiss it? (Obviously I can find the element and set it to hidden but that doesn't feel "clean").
This discussion has been closed.
Replies
The "fix" in DataTables would be to modify the $ajax call's error handler to hide the processing element, but I'm reluctant to do that since it will make it less likely the developer will see the problem.
Allan
Allan
In the end, I added a fnServerData handler and in the $.ajax call, I added:
[code]"error": handleAjaxError[/code]
In the function handleAjaxError, among other cleanup, I called
[code]table.fnProcessingIndicator( false );[/code]
db
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback,
"timeout": 15000, // optional if you want to handle timeouts (which you should)
"error": handleAjaxError // this sets up jQuery to give me errors
} );
},
[/code]
And then my error handling function:
[code]
function handleAjaxError( xhr, textStatus, error ) {
if ( textStatus === 'timeout' ) {
alert( 'The server took too long to send the data.' );
}
else {
alert( 'An error occurred on the server. Please try again in a minute.' );
}
myDataTable.fnProcessingIndicator( false );
}
[/code]
And then finally, code I got from elsewhere on this site to define that function I'm using to turn off the processing indicator:
[code]
jQuery.fn.dataTableExt.oApi.fnProcessingIndicator = function ( oSettings, onoff ) {
if ( typeof( onoff ) == 'undefined' ) {
onoff = true;
}
this.oApi._fnProcessingDisplay( oSettings, onoff );
};
[/code]
Hope this helps.
db
This solution worked perfectly. Thanks so much!