Problem with parsing parametres - server side

Problem with parsing parametres - server side

wolfy2kwolfy2k Posts: 2Questions: 1Answers: 0
edited December 2014 in Free community support

Hello there,
I am dealing with an issue, that I am not able to parse incoming parameters from DataTable on the server.

var table = AJS.$(this.tableElement).DataTable({
            bPaginate: true,
            bProcessing: true,
            bDeferRender: true,
            bServerSide: true,
            ajax: {
                url: AJS.contextPath() + this.serverSidePath,
                type: 'POST'
            },
            bStateSave: saveable,
            bSort: sortable,
            aoColumns: [
                { "data": "name" },
                { "data": "milestone" },
                { "data": "customer" },

            ],
            sDom: "ilrtp",
           
        });

With the simple parameters it is ok, eg. draw, start and legth I get properly. But for "search" parameter only thing I get is "[object Object]". For "columns" parameter I get "[object Object] [object Object] [object Object]". I sniffed the packets from data table and the problem is already on javascript.

http://10.156.9.142/example/server_side/scripts/server_processing.php?draw=1&columns=%5Bobject+Object%5D&columns=%5Bobject+Object%5D&columns=%5Bobject+Object%5D&order=%5Bobject+Object%5D&start=0&length=10&search=%5Bobject+Object%5D&_=1418208644787

I checked the DataTables source code and in function _fnBuildAjax() where the ajax is created the variable baseAjax has parameter data, where the javascript object is assigned. Should not be there something like JSON stringify()? Or something simmilar.

Any ideas? Am I doing something wrong?

Answers

  • wolfy2kwolfy2k Posts: 2Questions: 1Answers: 0
    edited December 2014

    Ok, so if somebody had a similar problem. I think it usually does not happen, however I am working on JIRA plugins and may be this issue is caused by some Atlassian changes in javascript. I dont know why that happens, but I wrote function that parses general "data" object into url parameters based on DataTables documentation. It can be put into DataTables source code...

       function _fnParseToParam(data, parent) {
                var s = "";
                if (parent == null)
                parent = "";
    
                for ( var property in data) {
                if (data.hasOwnProperty(property)) {
                    var object = data[property];
                    if (parent != "") // from second level => brackets
                    property = "[" + property + "]";
    
                    if (typeof object === "object" || $.isArray(object)) {
                    if (isNaN(property))
                        s = s + _fnParseToParam(object, parent + property);
                    else
                        s = s + _fnParseToParam(object, parent);
                    } else {
                    s = s + parent + property + "=" + object + "&";
                    }
                }
                }
                return s;
            }
     ....
    var param = _fnParseToParam(data);
    var baseAjax = {
        "data" : param,
     .... 
    
    
This discussion has been closed.