fnReloadAjax problem with fnReloadAjax and POST method

fnReloadAjax problem with fnReloadAjax and POST method

ambesangevishalambesangevishal Posts: 4Questions: 0Answers: 0

Datatables is a great work done. I use datatables in my project for many features.

I have a Search feature where in my search criteria and results are displayed on same page. I am using fnReloadAjax on click of search button click. Below is my datatable definition

oSimResultsTable = $("#simSearchResultsDataTable")
        .dataTable(
                {
                    "sDom" : "ptprP",
                    "iDisplayLength" : iDisplayLength,
                    "iDisplayStart" : 0,
                    "bAutoWidth" : true,
                    "bProcessing" : false,
                    "bServerSide" : true,
                    "sServerMethod": "POST",
                    "sPaginationType" : "full_numbers",
                    "sAjaxSource" : "SearchSim?userAction=refresh&&isClearCriteria=false",
                    "fnPreDrawCallback" : function(oSettings) {
                    // skipping code here
                    },
                    "fnDrawCallback" : function(oSettings) {

                    // Skipping code here ...
                    },
                    "fnServerParams": function ( aoData ) {
                        aoData.push( { "name": "simSearchCriteria.simName", "value":jQuery("#simName").val() } );
                        aoData.push( { "name": "simSearchCriteria.engineModel", "value":jQuery("#engineModel").val() } );
                        aoData.push( { "name": "simSearchCriteria.opcode", "value":jQuery("#opcode").val() } );
                        aoData.push( { "name": "simSearchCriteria.ecuLevel", "value":jQuery("#ecuLevel").val() } );
                        aoData.push( { "name": "simSearchCriteria.compatCode", "value":jQuery("#compatCode").val() } );
                        aoData.push( { "name": "simSearchCriteria.userId", "value":jQuery("#userId").val() } );
                    },
                    "fnServerData" : function(sSource, aoData, fnCallback,
                            oSettings) {

                        if (!isClearSimSearchCriteria) {
                            oSettings.jqXHR = $
                                    .ajax({
                                        "dataType" : 'json',
                                        "type" : "POST",

// "url": sSource+'?'+$.param(aoData),
// "data": JSON.stringify(aoData),
"url" : sSource,
"data" : aoData,
"success" : function(json) {

                                                fnCallback(json);

                                        },
                                        "error" : function(xhr, status,
                                                error) {

                                        //skipping code here
                                        }
                                    });
                        } else {
                                //skipping code here
                        }
                    },

}

Below is the code for ReloadAjax plug in I am using

$.fn.dataTableExt.oApi.fnReloadAjax = function(oSettings, sNewSource,
fnCallback, bStandingRedraw) {
if (sNewSource !== undefined && sNewSource !== null) {
oSettings.sAjaxSource = sNewSource;
}

// Server-side processing should just call fnDraw if (oSettings.oFeatures.bServerSide) {
    this.fnDraw();
    return;
}

this.oApi._fnProcessingDisplay(oSettings, true);
var that = this;
var iStart = oSettings._iDisplayStart;
var aData = [];

this.oApi._fnServerParams(oSettings, aData);

oSettings.fnServerData.call(oSettings.oInstance, oSettings.sAjaxSource,
        aData, function(json) {
            /* Clear the old information from the table */
            that.oApi._fnClearTable(oSettings);

            /* Got the data - add it to the table */
            var aData = (oSettings.sAjaxDataProp !== "") ? that.oApi
                    ._fnGetObjectDataFn(oSettings.sAjaxDataProp)(json)
                    : json;

            for ( var i = 0; i < aData.length; i++) {
                that.oApi._fnAddData(oSettings, aData[i]);
            }

            oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();

            that.fnDraw();

            if (bStandingRedraw === true) {
                oSettings._iDisplayStart = iStart;
                that.oApi._fnCalculateEnd(oSettings);
                that.fnDraw(false);
            }

            that.oApi._fnProcessingDisplay(oSettings, false);

            /* Callback user function - for event handlers etc */
            if (typeof fnCallback == 'function' && fnCallback !== null) {
                fnCallback(oSettings);
            }
        }, oSettings);

};

Below is my search button click java script function
function searchSim(){
oSimResultsTable.fnReloadAjax("SearchSim?userAction=search");
}
The functionality works fine when I dont use fnServerParams and pass form data in query string.
I am using fnServerParams to avoid scripting attacks.

The issue I am facing is fnServerParams does not pass the parameters to server always. Specifically when I switch IE browser mode using Compatibility mode option.

I already struggled a lot through many discussions available on this forum but no luck with any of them.

Please help in this

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I would suggest updating to 1.10 and using ajax.reload() it will automatically use whatever configuration you have setup for your DataTable. Otherwise, it looks like a modification to fnReloadAjax might be required.

    Allan

  • ambesangevishalambesangevishal Posts: 4Questions: 0Answers: 0
    edited May 2014

    I can not change the data table version right now. what changes would be required in fnReloadAjax ? could you please update me on latest fnReloadAjax plug in which will solve this problem?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Not sure to be honest at the moment. I'd be happy to take a look at it under the quick support option.

    Allan

This discussion has been closed.