Handing HTTP 30x..40x..50x

Handing HTTP 30x..40x..50x

sukkadsukkad Posts: 2Questions: 0Answers: 0
edited June 2013 in General
Hi I am using Datatables with server-side and AJAX. Every thing works okay until session expires or some error is thown by server. I am using
[code]$.fn.dataTableExt.sErrMode = 'throw';[/code]
to avoid pop-up. I have to reload page when exception happens. I tried putting try/catch(e){document.location.reload()} around my datatable initialization call
[code]$('.datatable').dataTable( .....)[/code]
This does not seem to work though. I see exception in chrome toolbar(developer tools).
What am I doing wrong? Any suggestions on this?

Thanks and advance.

Regards

Replies

  • sukkadsukkad Posts: 2Questions: 0Answers: 0
    Found solution. I was able to do it with fsServerData parameter. In case anyone needs something similar, this is how you can do. Error Handler handleAjaxError can be modified based on your requirement.
    [code]
    function handleAjaxError( xhr, textStatus, error ) {
    document.location.reload(true);
    }
    $(document).ready(function() {
    $.fn.dataTableExt.sErrMode = 'throw';
    $('.datatable').dataTable( {
    "sDom": "<'row-fluid'<'span4'l><'span8'f>r>t<'row-fluid'<'span4'i><'span8'p>>",
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "your URL",
    "sPaginationType": "bootstrap",
    "oLanguage": {
    "sLengthMenu": "_MENU_ records per page"
    },
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "type": "GET",
    "url": sSource,
    "data": aoData,
    "success": fnCallback,
    "timeout": 15000,
    "error": handleAjaxError
    "error": handleAjaxError
    });
    },

    ......
    [/code]

    If anyone has better suggestion, please post it.
This discussion has been closed.