Ajax object from RPC service

Ajax object from RPC service

SylviaSylvia Posts: 7Questions: 2Answers: 0

I have created an RPC Service and have called this service with $.getJSON("/getPackageList") with no issues. However when I call this same service via a datatable:

$('#a_table').DataTable({
ajax{
url: "/getPackageList"
dataSrc: "result"
},

columns:[
{"data": "lable1"},
{"data": "lable2"},
{"data": "lable3"}
]

})

... I get an error "DataTables warning: table id=a_table - [object Object]". The console also provides an error in the GET request:
{"error":{"parameterValue":null,"message":"CWRPC0008E: The parameters in the request do not match the
parameters that are defined for the getPackageList method.","name":"JSONRPCError","parameterIndex":null
,"code":"CWRPC0008E","methodName":"getPackageList","stackTrace":null,"serviceName":"PackageToolService"
}}

I have removed the validators from my web service. I have also loaded the url directly in my broswer, copied and pasted the Json data in a file and when calling the file directly within the Datatable: "url: "/myfile.json" my datatable loads fine.

I am not sending parameters with my request. Any help would be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    What , exactly, is the structure of the data returned from the RPC call?

  • SylviaSylvia Posts: 7Questions: 2Answers: 0

    Thanks ThomD. Here is the structure of the data returned by the RPC call.

    {"result":[

    {
        "label1" : "aPkgName",
        "label2" : "aVersionName",
        "label3" : "aURL"
    }
    

    ]}

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    You have spelled the word "label" two different ways.

  • SylviaSylvia Posts: 7Questions: 2Answers: 0

    ok ... that was just my bad typing on my part.... however I have double checked and this is not the issue. Somehow the ajax call from the datatable sends in a parameter and the getJSON call does not. Here is the "actual" code:

    //getJSON works!
    $.getJSON("/jospat/RPCAdapter/httprpc/TestObjService/getTestObjList", function( data ) {
    alert(JSON.stringify(data));
    });

    //Datatable NOT working! 
    $('#ospat_data').DataTable( {
        ajax: {
            url:  "/jospat/RPCAdapter/httprpc/TestObjService/getTestObjList",
            dataSrc: "result",
        },
    
        columns: [
            { data: "triangle" },
            { data: "box" },
            { data: "circle" },
            { data: "square" },
            { data: "oval" }
          ]
    

    })

    For the getJSON call the Console displays:

    NO Params tab and Response Tab has...

    {"result":[{"triangle":"Trangle1","box":"box1","square":"square1","circle":"circle1","oval":"oval1"}
    ]}

    For the Datatable call the Console displays

    A Params tab with this value: "_ 1443576286438"

    Resonse Tab with this error:

    {"error":{"parameterValue":null,"message":"CWRPC0008E: The parameters in the request do not match the
    parameters that are defined for the getTestObjList method.","name":"JSONRPCError","parameterIndex":null
    ,"code":"CWRPC0008E","methodName":"getTestObjList","stackTrace":null,"serviceName":"TestObjService"}
    }

    When I copy and paste the response from the getJSON call into a file and call the file instead of the url it works.

    //Datatable THIS WORKS!
    $('#ospat_data').DataTable( {
    ajax: {
    url: "data/result.json",
    dataSrc: "result",
    },

        columns: [
            { data: "triangle" },
            { data: "box" },
            { data: "circle" },
            { data: "square" },
            { data: "oval" }
          ]
    

    })

    File: data/result.json has:

    {"result":
    [{
    "triangle":"Trangle1",
    "box":"box1",
    "square":"square1",
    "circle":"circle1",
    "oval":"oval1"}
    ]}

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    Answer ✓

    OK, 'm with you now. Check out this for debugging what DataTables thinks is happening.

    https://datatables.net/reference/api/ajax.params()

    I don't use DT's ajax call. I use $getJSON because I'm more comfortable with it. As part of the success of that call I initialize my dataTables object. I have a small data set, so I just load it all and do "everything" client side.

    The only reference I can find in the documentation about params is under serverSide processing. If true, DT will add paging and control parameters.

  • SylviaSylvia Posts: 7Questions: 2Answers: 0

    Thanks ThomD. I did a "work-around" where I am also using the $getJSON call instead of the DTs ajax call as you mentioned you do. Thanks for you feedback and replies.

This discussion has been closed.