How to use in ajax code error returned data?

How to use in ajax code error returned data?

FioreFiore Posts: 1Questions: 1Answers: 0

Hi, I'm using datatable with server side processig and I found here https://datatables.net/manual/server-side that I can use the parameter "error" in the returned data. But I can't find an example that tells me how to use this parameter in javascript.

My server side code is:

        $tableData = array(
                'sEcho'=> intval($_POST['sEcho']),
                'iTotalRecords' => 0,
                'iTotalDisplayRecords' => 0,
                'aaData' => [],
                'error' => 'Prova di errore'
                     );

My ajax code is:

var oTable = $('#table').dataTable( {
    "bFilter": false,
    "bSort" : false,
    "bPaginate": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "prova.php",
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
          aoData.push( { "name": "minDate", "value": $('#date-from').val() },
                       { "name": "maxDate", "value": $('#date-to').val() }
          );
          oSettings.jqXHR = $.ajax( {
            "dataType": 'json',
            "type": "POST",
            "url": sSource,
            "data": aoData,
            "success": fnCallback,
            "error": function(xhr, error, thrown) { 
                alert("Date not valid!"); 
            }
          } );
    }
 } );

How do I change the ajax code to use the parameter error that I get from the server?
I would to produce alert with the error from the server.

Many Thanks

This discussion has been closed.