Process authenticated flag in json from server before letting Datatables process the response?
Process authenticated flag in json from server before letting Datatables process the response?
I'm using datatables with Django on the server. I have it all working nicely but one case is causing me grief. If a user logs out from the site in one browser tab (or is logged out due to inactivity) the page using Datatables gives errors. I have a Django view decorator that inserts a flag into the json response indicating if the user is authenticated or not. The javascript in my other pages checks this flag before continuing. But I can't do this with Datatables because I'm using this code to tell the table to update itself:
[code]event_table.fnDraw(true);[/code]
Is there any way to process the json response in my own code before Datatables processes it? Or is there a better way to handle this situation?
Thanks
[code]event_table.fnDraw(true);[/code]
Is there any way to process the json response in my own code before Datatables processes it? Or is there a better way to handle this situation?
Thanks
This discussion has been closed.
Replies
put this "fnServerData" function in your initializer
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.getJSON( sSource, aoData, function (json) {
if ({your criteria in the json in case of error/redirect}) { your code in case of error }
else fnCallback(json);
} );
},
[/code]
see also: http://www.datatables.net/ref#fnServerData