jQuery, DataTables, ajax error handling: get rid of "Processing" message -
i using jquery datatables, ajax , bootstrap in small project. working , testing error states. have setup html datatables table. there table-responsive
div surrounding <table>
.
<div id="errordiv"></div> <div id="resulttablediv" class="table-responsive"> <table id="resulttable" class="table table-striped table-bordered table-hover table-condensed" cellspacing="0"> <thead> <tr> <th>...</th> ... </tr> </thead> <tfoot> <tr> <th>...</th> ... </tr> </tfoot> </table> </div> </div>
in datatables init setup ajax call , specify error
callback function. "works" in can force error in server side ajax code , callback fired. can handle returned error want.
my issue when ajax call starts table body "replaced" processing
message. that's fine except when ajax reports error via callback processing message still there , have yet figure out how make go away via datatables methods or api calls.
my error callback looks like
function ajaxerror(jqxhr, textstatus, errorthrown) { var obj = jquery.parsejson(jqxhr.responsetext); if (obj && obj.error) { $('#errordiv').html("<p>" + obj.error + "</p>"); } }
i have "global" variable holds datatables table definition. set in jquery ready function
var table; $(function () { $('#errordiv').empty(); $('#resulttable').show(); table = $('#resulttable').datatable({ paging: false, processing: true, autowidth: false, ordering: false, ajax: { url: "ions.cgi", datatype: 'json', datasrc: "list", error: ajaxerror }, ...
in error callback have tried of following:
table.clear().draw(); // nothing table.fnredraw(); // says function not exist
in error state how should processing
message reset?
the element shows processing message gets id <idoftable>_processing
, hide using:
$('#resulttable_processing').hide();
this might have changed, , id different, concept stands, can find out how identify element , hide it. datatables show again if has to.
also, want processing message showing in other ocassions? because can make never appear using processing: false
on datatable's options (or not setting @ all, since it's default behaviour not show it).
Comments
Post a Comment