Invalid JSON response and Requested unknown parameter errors

Invalid JSON response and Requested unknown parameter errors

SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0
edited May 2016 in Free community support

Hi

I would be grateful for some help if possible. I am returning JSON via an AJAX call and am getting the errors as per the question subject.

The first error that is shown is "Requested unknown parameter '1' for row 0, column 1 " and then an Invalid JSON response once this error is cleared

Below is my code

function populateTable(json, tableId) {
            try {
                var table = $('#table_' + tableId).DataTable({
                    "processing": true,
                    "serverSide": true,
                    "data": json.d,
                    "deferRender": true,
                    "columns:": [

                        { "data": "CaseHandlerStaffNumber" },
                        { "data": "RiskProfileText" },
                        { "data": "AssignedCheckerStaffNumber" },
                        { "data": "FeedbackUserStaffNumber" },
                        { "data": "ComplaintRef" },
                        { "data": "ChildComplaintRef" },
                        { "data": "CaseTypeText" },
                        { "data": "CheckGrade" }
                    ]
                });
            } catch (e) {

            }
        }

I get another error message directing me to datatables.net/tn/1 however checking on JSONLint the JSON being returned is a valid response and I am not getting any 404 or 500 response when checking the returns.

I get all as 200OK

and this is an example of the JSON that is being passed in

{
    "data": [{
        "CaseHandlerStaffNumber": "12345678",
        "RiskProfileText": "Low Risk FOS",
        "AssignedCheckerStaffNumber": "77665544",
        "FeedbackUserStaffNumber": null,
        "ComplaintRef": "999999",
        "ChildComplaintRef": "2333",
        "CaseTypeText": "FOS Submission",
        "CheckGrade": "Ungraded"
    }]
}

I would be grateful for any help that can be offered on this thanks

Simon

This question has an accepted answers - jump to answer

Answers

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    sorry about the poor formatting

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Hi,

    With your configuration above, it suggests that your DataTable might have 9 or more columns rather than the 8 configured in Javascript. Might that be the case? They need to match.

    Another point - you can't have serverSide enabled and not provide an ajax option. The table needs to know where to request more data from when it redraws the table. This section describes server-side and client-side processing.

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0
    edited May 2016

    Hi Allan, when the headers and footers for the table is created dynamically there are only 8 columns same as the configuration I have posted.

    please see the c# code below of how I am producing the tale and the JSON response.

    protected void CreateOutputDataGrid(DataTable dtMC, string CheckStatusId)
    {
        StringBuilder sb = new StringBuilder();
    
        sb.AppendLine(string.Format("<table id='table_{0}' style='width:100% !important' class='table table-hover table-striped'>", CheckStatusId));
    
        hidTableListForSearch.Value += "table_" + CheckStatusId + ",";
    
        sb.AppendLine("<thead>");
        sb.AppendLine("<tr>");
        sb.AppendLine("<th>Case Handler</th>");
        sb.AppendLine("<th>Risk profile</th>");
        sb.AppendLine("<th>Checker</th>");
        sb.AppendLine("<th>Feedback sent to</th>");
        sb.AppendLine("<th>Complaint Ref</th>");
        sb.AppendLine("<th>Child Complaint Ref</th>");
        sb.AppendLine("<th>Case Type</th>");
        sb.AppendLine("<th>Check Grade</th>");
        sb.AppendLine("</tr>");
        sb.AppendLine("</thead>");
    
    
        sb.AppendLine("<tfoot class='foot'>");
        sb.AppendLine("<tr>");
        sb.AppendLine("<th>Case Handler</th>");
        sb.AppendLine("<th>Risk profile</th>");
        sb.AppendLine("<th>Checker</th>");
        sb.AppendLine("<th>Feedback sent to</th>");
        sb.AppendLine("<th>Complaint Ref</th>");
        sb.AppendLine("<th>Child Complaint Ref</th>");
        sb.AppendLine("<th>Case Type</th>");
        sb.AppendLine("<th>Check Grade</th>");
        sb.AppendLine("</tr>");
        sb.AppendLine("</tfoot>");
    
        sb.AppendLine("<tbody>");
    
        sb.AppendLine("</tbody>");
        sb.AppendLine("</table>");
    
        HiddenField hiddenField = new HiddenField();
        hiddenField.ID = string.Format("hidJson_tbl_{0}", CheckStatusId);
        PlaceHolderTabPanes.Controls.Add(hiddenField);
    
        PlaceHolderTabPanes.Controls.Add(new LiteralControl(sb.ToString()));
    
    }
    
    
    [System.Web.Services.WebMethod()]
    public static object GetDataTables(string checkId, int userId)
    {
    
        int CheckStatusId = Convert.ToInt32(checkId.Replace("hidJson_tbl_", ""));
    
        TeamChecks tc = new TeamChecks();
    
        DataTable dtMc = default(DataTable);
        dtMc = tc.Get_DatatableFor_GridView(userId, CheckStatusId);
    
        DataTable dt = new DataTable();
        dt.Columns.Add("CaseHandlerStaffNumber");
        dt.columns.@add("RiskProfileText");
        dt.columns.@add("AssignedCheckerStaffNumber");
        dt.columns.@add("FeedbackUserStaffNumber");
        dt.columns.@add("ComplaintRef");
        dt.columns.@add("ChildComplaintRef");
        dt.columns.@add("CaseTypeText");
        dt.Columns.Add("CheckGrade");
    
        foreach (var row in dtMc.Rows) {
                dt.Rows.Add(row("CaseHandlerStaffNumber"), row("RiskProfileText"), row("AssignedCheckerStaffNumber"), row("FeedbackUserStaffNumber"), row("ComplaintRef"), row("ChildComplaintRef"), row("CaseTypeText"), row("CheckGrade"));
        }
        string jsonResult = null;
        jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
        jsonResult = jsonResult.Replace("[{", "{\"data\" :[{").Replace("}]", "}]}");
        return jsonResult;
    
    }
    
    
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Can you give me a link to the page or use the debugger so I can take a look at what is happening please?

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    Unfortunately I cant as its all internal to the location where I am working. What do you need from the debugger and I will post it here for you.

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    If you could give me an email address I can send you some images of what I am seeing and detail what I would expect to see.

    In areas where I should see only two rows of data I am getting circa 4k rows of "", null, null .... null

    and where I should see no data I am seeing

    [, null, null,..... null
    ], null, null,..... null

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    ok, so the error messages have stopped, but the issue that remains is no data comes into my tables

    what I have changed is

    "data": json, to "data": json.d,

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    You can PM me the link to the debugger trace by clicking my name above and then the "Send message" button.

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    its an internal application so no outside access to it im afraid. im not getting anything in the debugger either that jumps out but if you tell me the steps you need me to follow I will follow them and send you the results

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    Allan, I am pretty much back at square one, request unknown parameter '1' for row 0 column 1.

    Any ideas on what I should do as I am just going round in circles

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Can you tell me the six letter debug code from the debugger please. I wasn't expecting you to use the debugger yourself! Its to give me the information that will hopefully let me answer your question.

    The error you are getting means that DataTables can't find the data for column index 1 in row 0. Without knowing how your DataTable is configured, the data it is being loaded with and the HTML for the table, I'd just be guessing (and the tech note the error links to is for that).

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    Im not getting any errors or error codes in the debugger, just your alert window unless im looking in the wrong place.

    The only thing I get up is the alert window telling me my issue

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    When you use the DataTables debugger, when complete it should say:

    Upload complete - debug code: {code}

    I need to know that code so I can take a look at the issue.

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    sorry, I thought you meant in ie, its been a long few days the code is ekazaz

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Thank you. There are 12 tables in the debug trace. Which is the one you are getting error messages from. Can you also give me the exact error text please.

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    all of them and the error message is exactly the same for each;

    "Datatables warning: table id=table_{tablenumber} - Requested unknown parameter '0' for row 0, column 0. For more information on this error please see...."

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Ah!

    "data ":

    It has a space at the end of the data parameter string! That makes it not the same parameter as columns.data and thus it defaults to be the default data source of the column index, hence the error message.

    Remove that string in all of your column definitions and it should work.

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    we've moved forward now which is good, still the same error on various tables with data but this time its consistent with;

    "Datatables warning: table id=table_{tablenumber} - Requested unknown parameter '1' for row 60 , column 1. For more information on this error please see...."

    and

    "Datatables warning: table id=table_{tablenumber} - Requested unknown parameter '1' for row 63 , column 1. For more information on this error please see...."

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    ok, so have moved on a little this morning, I am now getting an error

    "Datatables warning: table id=table_{tablenumber} - Requested unknown parameter 'CaseHandlerStaffNumber' for row 0, column 0. For more information on this error please see...."

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Can you give me an updated debugger link please?

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    I am trying to get it but I get a message saying webpage is not responding due to a long running script.

    I will let you know when its done, but its been going for 10 mintues now

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Its probably not going to load in that case - there is a limit on the amount of data it can upload. One option would be to create a page with a single table in it, and just a subset of the data (a single row for example) - it should fly through that and allow me to see the data for the table.

    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    ok, I will try that

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    Hi sorry for the delay, the code is evemuv

    you will see 12 tables on the page, but only one has been attempted to be populated. The way the original developer has coded the page to build the tables, if I disrupt that flow the page breaks...

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0
    edited May 2016

    I have tried some new things and the debug code is unipab

    my new JQuery is

    $(document).ready(function () {
         $("[id^='hidJson_tbl_']").each(function () {
            var id = this.id;
            console.log(id);
    
            var params = {
                checkId: id,
                userId: $("#hidUserId").val()
            };
    
            var tableId = id.replace("hidJson_tbl_", "");
    
            $.ajax({
                type: "POST",
                url: "TeamChecks.aspx/GetDataTables",
                data: JSON.stringify(params),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    //console.log(data.d);
                    //populateTable(data, tableId);
                     var dataSet = data.d;
                    var id = 'table_' + tableId;
                    $('#table_2').DataTable({
                        data: data.d,
                        columns: [
                                    { title: "CaseHandlerStaffNumber", data: "CaseHandlerStaffNumber" },
                                    { title: "RiskProfileText", data: "RiskProfileText" },
                                    { title: "AssignedCheckerStaffNumber", data: "AssignedCheckerStaffNumber" },
                                    { title: "FeedbackUserStaffNumber", data: "FeedbackUserStaffNumber" },
                                    { title: "ComplaintRef", data: "ComplaintRef" },
                                    { title: "ChildComplaintRef", data: "ChildComplaintRef" },
                                    { title: "CaseTypeText", data: "CaseTypeText" },
                                    { title: "CheckGrade", data: "CheckGrade" },
                        ]
                    });
    
                },
                error: function (data) {
                    console.log("error :" + data);
                }
            }
    
            );
        });
    

    The issue I get now is cannot reinitialise the table_2 along with Datatables warning: table id=table_{tablenumber} - Requested unknown parameter 'CaseHandlerStaffNumber' for row 0, column 0. For more information on this error please see.

    All this help is very much appreciated

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Answer ✓

    The debugger shows that the parameter passed into data is a string:

    "data": "[]",
    

    You could try using:

    data: JSON.parse( data.d ),
    

    That will convert a string (which the server-side appears to be returning) into a valid Javascript array of objects.

    Regards,
    Allan

  • SimonPrice3376SimonPrice3376 Posts: 25Questions: 5Answers: 0

    that worked along with some other little changes that I will post here in a moment

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Glad to hear I could help.

    Allan

This discussion has been closed.