How do I intercept an ajax call and pass additional parameters fnParams fnServerData details

How do I intercept an ajax call and pass additional parameters fnParams fnServerData details

gc_retrogressgc_retrogress Posts: 4Questions: 2Answers: 0

Here is my code...

jQuery(function() {
            var table = jQuery('#example').dataTable({
                "processing": true,
                "serverSide": true,
                                    "ajax": {
                    "url": "serverside",
                    "dataSrc": "jsondata"
                },
                "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {

                      oSettings.jqXHR = $.ajax( {
                        "dataType": 'json',
                        //"type": "POST",
                        "url": "serverside",
                        "data": aoData,
                        //"success": fnCallback
                      } );
                },
                                    "aoColumnDefs": [{ 
                        mData: "Id",
                        sType: "integer",
                        aTargets: [0] 
                    }, {
                        mData: "SerialId",
                        sType: "integer",
                        aTargets: [1]
                    }, {
                        mData: "critical",
                        sType: "string",
                        aTargets: [2], 
                    }
                                         ],
                                        });

Answers

  • gc_retrogressgc_retrogress Posts: 4Questions: 2Answers: 0
    edited June 2014

    Ok I solved the problem by using jQuery.ajaxSend(), I could not figure out datatable option...althougth I think preXhr event was close to helping me out..anyway here it is

        $( document ).ajaxSend(function( event, jqXHR, ajaxOptions ) {                  
                    var table = $('#example').dataTable();
                    var api = table.api();
                    var order = api.order();
                    //console.log("order details" + order[0][0]);
                    var objCols = table.fnSettings().aoColumns;
                    //console.log('Column name for order[0][0]' + objCols[0].mData);
                    var applicationUrl = "url.php";
                //  ajaxOptions.url = ajaxOptions.url+"&orderby="+objCols[order[0][0]].mData+"&orderdir="+order[0][1];
                    ajaxOptions.url = mdnsUrl+"?orderby="+objCols[order[0][0]].mData+"&orderdir="+order[0][1];                   
                //  console.log("URL"+ajaxOptions.url);
                });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Don't use ajax in combination with fnServerData - the two are mutually exclusive. Use only ajax to provide your own Ajax call, or better yet, if you just want to add extra data, simply use ajax.data.

    Allan

This discussion has been closed.