webapi returns datatable and get data using ajax giving error

webapi returns datatable and get data using ajax giving error

schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

i cannot define columns or headers it just returns datatable and convert that to datatable in the frontend

Answers

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Sorry but your problem description isn't detailed enough to understand the problem to help.

    Please provide more details including any error messages so we can offer suggestions. Post your Datatables init code. Better is a link to your page or test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    webapi get datatable because it creates dynamic columns and dynamic header. in

    ajax query
    $('#actualTable').DataTable( {
    ajax: {
    "url": 'http://localhost:64158/ProductionEfficiencyReport/GetActualTable',
    },
    });

    but still get error the returned data shows

    [
    {"Id":0,"Line":"PAIL3","1-Dec":14240.0,"2-Dec":null,"3-Dec":null,"4-Dec":6300.0,"5-Dec":14040.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,
    "13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,
    "26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null
    }
    ,{"Id":1,"Line":"DRLN1","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":2,"Line":"DRLN5","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":3,"Line":"DRLN6","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":5500.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":4,"Line":"LN03 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":5,"Line":"LN20 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":8662.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":6,"Line":"LN6 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":6894.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":7,"Line":"LN7 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":4092.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":8,"Line":"LN9 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":9,"Line":"PAIL2","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":7440.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":10,"Line":"LN2 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":2310.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,
    "22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,
    "30-Dec":null,"31-Dec":null}]

  • allanallan Posts: 63,446Questions: 1Answers: 10,465 Site admin

    You have a top level array of data. See this example for how to configure for that.

    You also have object based data. See the manual for how to configure for that.

    Allan

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    i know to use the above examples. but i cannot give the column names because that should be changed for every month so please help me

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited December 2023

    Use columns.title to define the header names.

    See this FAQ for getting the column names via ajax - assuming that is what you want to do.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    in the above example too how can i say the column null ? if u see above the data is monthly data every month the column headers change

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited December 2023

    I'm not sure I understand the question.

    You can use a variable to define the columns. You can programmatically define the columns based on the current month. Use something like this example to get the current month name:
    https://www.w3schools.com/jsref/jsref_getmonth.asp

    Then use that name to define the columns then apply to Datatables, for example:

    var monthName = 'Dec'  // Use a method of your choice to derive the month name
    
    var columns = [
      {data: 'id', title: 'ID'},
      {data: 'Line', title: 'Line'},
      {data: '1-' + monthName, title: '1-' + monthName},
    // Continue for all the days of the month
    ]
    
    $('#actualTable').DataTable( {
      ajax: {
        "url": 'http://localhost:64158/ProductionEfficiencyReport/GetActualTable',
      },
      columns: columns
    });
    

    You can use a loop to build the columns variable.

    If this doesn't help then please provide more specifics of what you are asking for. One or two sentences is not enough for me to understand what you want.

    Kevin

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited December 2023

    This example shows one option to fetch the columns via $.ajax(), as suggested in the FAQ:
    https://live.datatables.net/huyexejo/1800/edit

    It gets the column names from the column object key. You could also return the columns names in a separate object.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    Thanks this is so helpful but still why do i get this error when i try to click the url the data shows up

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    You will need to investigate what is returned by the server. Use the browser's network inspector. This SO thread might give some ideas.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0
    edited December 2023

    I changed everything but i get this error now

    jquery-3.3.1.min.js:2 Uncaught TypeError: Cannot use 'in' operator to search for 'length' in {data: 'Id', title: 'Id'} , {data:'Line', title: 'Line'} , {data: '1-Dec', title: '1-Dec'} , {data: '2-Dec', title: '2-Dec'} , {data: '3-Dec', title: '3-Dec'} , {data: '4-Dec', title: '4-Dec'} , {data: '5-Dec', title: '5-Dec'} , {data: '6-Dec', title: '6-Dec'} , {data: '7-Dec', title: '7-Dec'} , {data: '8-Dec', title: '8-Dec'} , {data: '9-Dec', title: '9-Dec'} , {data: '10-Dec', title: '10-Dec'} , {data: '11-Dec', title: '11-Dec'} , {data: '12-Dec', title: '12-Dec'} , {data: '13-Dec', title: '13-Dec'} , {data: '14-Dec', title: '14-Dec'} , {data: '15-Dec', title: '15-Dec'} , {data: '16-Dec', title: '16-Dec'} , {data: '17-Dec', title: '17-Dec'} , {data: '18-Dec', title: '18-Dec'} , {data: '19-Dec', title: '19-Dec'} , {data: '20-Dec', title: '20-Dec'} , {data: '21-Dec', title: '21-Dec'} , {data: '22-Dec', title: '22-Dec'} , {data: '23-Dec', title: '23-Dec'} , {data: '24-Dec', title: '24-Dec'} , {data: '25-Dec', title: '25-Dec'} , {data: '26-Dec', title: '26-Dec'} , {data: '27-Dec', title: '27-Dec'} , {data: '28-Dec', title: '28-Dec'} , {data: '29-Dec', title: '29-Dec'} , {data: '30-Dec', title: '30-Dec'} , {data: '31-Dec', title: '31-Dec'} ,
        at C (jquery-3.3.1.min.js:2:3527)
        at Function.each (jquery-3.3.1.min.js:2:2534)
        at w (jquery.dataTables.min.js:4:9852)
        at at (jquery.dataTables.min.js:4:14779)
        at jquery.dataTables.min.js:4:7019
        at st (jquery.dataTables.min.js:4:17261)
        at HTMLTableElement.<anonymous> (jquery.dataTables.min.js:4:6983)
        at Function.each (jquery-3.3.1.min.js:2:2573)
        at w.fn.init.each (jquery-3.3.1.min.js:2:1240)
        at w.fn.init.C [as dataTable] (jquery.dataTables.min.js:4:3487)
    C @ jquery-3.3.1.min.js:2
    each @ jquery-3.3.1.min.js:2
    w @ jquery.dataTables.min.js:4
    at @ jquery.dataTables.min.js:4
    (anonymous) @ jquery.dataTables.min.js:4
    st @ jquery.dataTables.min.js:4
    (anonymous) @ jquery.dataTables.min.js:4
    each @ jquery-3.3.1.min.js:2
    each @ jquery-3.3.1.min.js:2
    C @ jquery.dataTables.min.js:4
    P.fn.DataTable @ jquery.dataTables.min.js:4
    GetActualDataTable @ ProductionProjection.js:38
    (anonymous) @ ProductionProjection.js:28
    u @ jquery-3.3.1.min.js:2
    fireWith @ jquery-3.3.1.min.js:2
    k @ jquery-3.3.1.min.js:2
    (anonymous) @ jquery-3.3.1.min.js:2
    load (async)
    send @ jquery-3.3.1.min.js:2
    ajax @ jquery-3.3.1.min.js:2
    w.<computed> @ jquery-3.3.1.min.js:2
    getJSON @ jquery-3.3.1.min.js:2
    (anonymous) @ ProductionProjection.js:5
    dispatch @ jquery-3.3.1.min.js:2
    y.handle @ jquery-3.3.1.min.js:2
    
  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0
    edited December 2023
    function getDaysInMonth() {
     var month = new Date();
      const daysInMonth = new Date(month.getYear(), month.getMonth() + 1, 0).getDate();
      const daysArray = [];
      daysArray.push("{data: 'Id', title: 'Id'}");
      daysArray.push(",");
      daysArray.push("{data:'Line', title: 'Line'}");
      daysArray.push(",");
      for (let day = 1; day <= daysInMonth; day++) {
        const formattedDate = `${day}-${month.toLocaleString('default', { month: 'short' })}`;
        daysArray.push("{data: '"+ formattedDate +"', title: '"+ formattedDate +"'}");
        daysArray.push("," );
      }
      //return daysArray;
    const result = daysArray
      .map(element => {
        if (Array.isArray(element)) {
          return element.join(""); // Join array elements without separator
        } else {
          return String(element); // Convert other elements to strings
        }
      })
      .join(" ");
    return result; 
    }
    

    this is my javascript method

    below is the table

    function GetActualDataTable(){
    var monthName = new Date().toLocaleString('default', { month: 'short' });
    const daysArray =getDaysInMonth();
     var columns = [daysArray]
      $('#actualTable').DataTable( {
        ajax: {
              "url": 'http://localhost:64158/ProductionEfficiencyReport/GetActualTable',
              dataType: "jsonp",
            },
        columns:columns
       });
    }
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,446Questions: 1Answers: 10,465 Site admin

    Can you show me the JSON response from the server please? You might need to use ajax.dataSrc set to be an empty string (you will if the server is returning a top level array).

    Allan

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    i added the response before too

    [
    {"Id":0,"Line":"PAIL3","1-Dec":14240.0,"2-Dec":null,"3-Dec":null,"4-Dec":6300.0,"5-Dec":14040.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,
    "13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,
    "26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null
    }
    ,{"Id":1,"Line":"DRLN1","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":2,"Line":"DRLN5","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":3,"Line":"DRLN6","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":5500.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":4,"Line":"LN03 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":5,"Line":"LN20 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":8662.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":6,"Line":"LN6 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":6894.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":7,"Line":"LN7 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":4092.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":8,"Line":"LN9 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":9,"Line":"PAIL2","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":7440.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":10,"Line":"LN2 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":2310.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,
    "22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,
    "30-Dec":null,"31-Dec":null}
    ]

    this is the url method

    List<string> tableNames = context.Database.SqlQuery<string>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES " +
    "WHERE TABLE_TYPE = 'BASE TABLE'").ToList();
    string currentTableName = ""; string tableName = "";
    currentTableName = string.Format("TargetDailyData_{0}_{1}", DateTime.Now.Year, DateTime.Now.ToString("MMM"));
    tableName = tableNames.Find(s => s.Trim().Equals(currentTableName));
    string query = string.Format("SELECT * FROM {0}", tableName);
    DataTable dataTable = new DataTable();
    using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnectionString"].
    ConnectionString.ToString()))
    {
    connection.Open();
    using (SqlCommand command = new SqlCommand(query, connection))
    {
    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
    {
    adapter.Fill(dataTable);
    }
    }
    }
    return dataTable;

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Have you used the ajax.dataSrc setting that Allan suggested, like this example?

    There isn't an obvious issue from the JSON response you posted. Is the JSON response you posted from the browser's network inspector? If not please use the browser's network inspector to get the JSON response to post here.

    If you can't post a link to your page so we can take a look maybe the debugger can provide Allan enough information to help.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    yes i tried that
    $('#actualTable').DataTable( {
    ajax: {
    "url": 'http://localhost:64158/ProductionEfficiencyReport/GetActualTable',
    "dataType": "jsonp",
    "dataSrc":""
    },
    columns:columns
    });

  • allanallan Posts: 63,446Questions: 1Answers: 10,465 Site admin

    I would have expected that to work. If it isn't working for you, please link to a test case showing the issue so I can help to debug it.

    Allan

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    [{
    "Id": 0,
    "Line": "PAIL3",
    "1-Dec": 14240.0,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": 6300.0,
    "5-Dec": 14040.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 1,
    "Line": "DRLN1",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 0.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 2,
    "Line": "DRLN5",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 0.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": null,
    "13-Dec": null,
    "14-Dec": null,
    "15-Dec": null,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 3,
    "Line": "DRLN6",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 5500.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 4,
    "Line": "LN03 ",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 0.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": null,
    "13-Dec": null,
    "14-Dec": null,
    "15-Dec": null,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 5,
    "Line": "LN20 ",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 8662.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 6,
    "Line": "LN6 ",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 6894.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 7,
    "Line": "LN7 ",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 4092.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 8,
    "Line": "LN9 ",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 0.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 9,
    "Line": "PAIL2",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 7440.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }, {
    "Id": 10,
    "Line": "LN2 ",
    "1-Dec": null,
    "2-Dec": null,
    "3-Dec": null,
    "4-Dec": null,
    "5-Dec": 2310.0,
    "6-Dec": 0.0,
    "7-Dec": 0.0,
    "8-Dec": 0.0,
    "9-Dec": null,
    "10-Dec": null,
    "11-Dec": null,
    "12-Dec": 0.0,
    "13-Dec": 0.0,
    "14-Dec": 0.0,
    "15-Dec": 0.0,
    "16-Dec": null,
    "17-Dec": null,
    "18-Dec": null,
    "19-Dec": null,
    "20-Dec": null,
    "21-Dec": null,
    "22-Dec": null,
    "23-Dec": null,
    "24-Dec": null,
    "25-Dec": null,
    "26-Dec": null,
    "27-Dec": null,
    "28-Dec": null,
    "29-Dec": null,
    "30-Dec": null,
    "31-Dec": null
    }]

    this is the response from browser

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Do you get any errors, either alerts or in the console?

    In your last code snippet you have "dataType": "jsonp",. But it doesn't look like your server is responding with a JSONP response as it should also contain a function name. Use the browser's network inspector to see the request payload and response. You will see both are wrapped in a function, something like this jQuery37007004015063149109_1702421439731({ ... }). Maybe your server doesn't support JSONP or you need to enable it if you want to use it.

    Or, remove "dataType": "jsonp", if your server doesn't support it.

    Its difficult to troubleshoot this problem because you post a code snippet or JSON response without details of your current Datatables configuration and what errors you are getting. This is why we are asking for a link to your page or test case that replicates the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    {\"Id\":0,\"Line\":\"PAIL3\",\"1-Dec\":14240.0,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":6300.0,\"5-Dec\":14040.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":1,\"Line\":\"DRLN1\",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":0.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":2,\"Line\":\"DRLN5\",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":0.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":null,\"13-Dec\":null,\"14-Dec\":null,\"15-Dec\":null,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":3,\"Line\":\"DRLN6\",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":5500.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":4,\"Line\":\"LN03 \",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":0.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":null,\"13-Dec\":null,\"14-Dec\":null,\"15-Dec\":null,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":5,\"Line\":\"LN20 \",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":8662.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":6,\"Line\":\"LN6 \",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":6894.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":7,\"Line\":\"LN7 \",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":4092.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":8,\"Line\":\"LN9 \",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":0.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":9,\"Line\":\"PAIL2\",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":7440.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null},{\"Id\":10,\"Line\":\"LN2 \",\"1-Dec\":null,\"2-Dec\":null,\"3-Dec\":null,\"4-Dec\":null,\"5-Dec\":2310.0,\"6-Dec\":0.0,\"7-Dec\":0.0,\"8-Dec\":0.0,\"9-Dec\":null,\"10-Dec\":null,\"11-Dec\":null,\"12-Dec\":0.0,\"13-Dec\":0.0,\"14-Dec\":0.0,\"15-Dec\":0.0,\"16-Dec\":null,\"17-Dec\":null,\"18-Dec\":null,\"19-Dec\":null,\"20-Dec\":null,\"21-Dec\":null,\"22-Dec\":null,\"23-Dec\":null,\"24-Dec\":null,\"25-Dec\":null,\"26-Dec\":null,\"27-Dec\":null,\"28-Dec\":null,\"29-Dec\":null,\"30-Dec\":null,\"31-Dec\":null}

    with the networkinspector log i think this is the data it is giving me back

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited December 2023

    The backslashes in front of the double quotes (\") suggest that the response is being JSON encoded twice by your server code. The second JSON encoding is escaping the double quotes.

    It might be a copy and paste error but the row data needs to be in an array, so it should look like this without the escaped quotes and in an array:

    [
        {
            "Id": 0,
            "Line": "PAIL3",
            "1-Dec": 14240,
            "2-Dec": null,
            "3-Dec": null,
            "4-Dec": 6300,
            "5-Dec": 14040,
            "6-Dec": 0,
            "7-Dec": 0,
            "8-Dec": 0,
            "9-Dec": null,
            "10-Dec": null,
            "11-Dec": null,
            "12-Dec": 0,
            "13-Dec": 0,
            "14-Dec": 0,
            "15-Dec": 0,
            "16-Dec": null,
            "17-Dec": null,
            "18-Dec": null,
            "19-Dec": null,
            "20-Dec": null,
            "21-Dec": null,
            "22-Dec": null,
            "23-Dec": null,
            "24-Dec": null,
            "25-Dec": null,
            "26-Dec": null,
            "27-Dec": null,
            "28-Dec": null,
            "29-Dec": null,
            "30-Dec": null,
            "31-Dec": null
        },
    ...
        {
            "Id": 10,
            "Line": "LN2 ",
            "1-Dec": null,
            "2-Dec": null,
            "3-Dec": null,
            "4-Dec": null,
            "5-Dec": 2310,
            "6-Dec": 0,
            "7-Dec": 0,
            "8-Dec": 0,
            "9-Dec": null,
            "10-Dec": null,
            "11-Dec": null,
            "12-Dec": 0,
            "13-Dec": 0,
            "14-Dec": 0,
            "15-Dec": 0,
            "16-Dec": null,
            "17-Dec": null,
            "18-Dec": null,
            "19-Dec": null,
            "20-Dec": null,
            "21-Dec": null,
            "22-Dec": null,
            "23-Dec": null,
            "24-Dec": null,
            "25-Dec": null,
            "26-Dec": null,
            "27-Dec": null,
            "28-Dec": null,
            "29-Dec": null,
            "30-Dec": null,
            "31-Dec": null
        }
    ]
    

    Check the server script to see where the data is being encapsulated twice. Otherwise use ajax.dataSrc as a function, see last example in the docs, to use JSON.parse() to decapsulate the data.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    jsonp cannot be removed i was getting 200 ok response and i tried to convert in to string and changed the url but still i get error
    [{"Id":0,"Line":"PAIL3","1-Dec":14240.0,"2-Dec":null,"3-Dec":null,"4-Dec":6300.0,"5-Dec":14040.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":1,"Line":"DRLN1","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":2,"Line":"DRLN5","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":3,"Line":"DRLN6","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":5500.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":4,"Line":"LN03 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":null,"13-Dec":null,"14-Dec":null,"15-Dec":null,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":5,"Line":"LN20 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":8662.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":6,"Line":"LN6 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":6894.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":7,"Line":"LN7 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":4092.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":8,"Line":"LN9 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":0.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":9,"Line":"PAIL2","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":7440.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null},{"Id":10,"Line":"LN2 ","1-Dec":null,"2-Dec":null,"3-Dec":null,"4-Dec":null,"5-Dec":2310.0,"6-Dec":0.0,"7-Dec":0.0,"8-Dec":0.0,"9-Dec":null,"10-Dec":null,"11-Dec":null,"12-Dec":0.0,"13-Dec":0.0,"14-Dec":0.0,"15-Dec":0.0,"16-Dec":null,"17-Dec":null,"18-Dec":null,"19-Dec":null,"20-Dec":null,"21-Dec":null,"22-Dec":null,"23-Dec":null,"24-Dec":null,"25-Dec":null,"26-Dec":null,"27-Dec":null,"28-Dec":null,"29-Dec":null,"30-Dec":null,"31-Dec":null}]

    this is the network response but now under datatable i still get the error

  • allanallan Posts: 63,446Questions: 1Answers: 10,465 Site admin

    Honestly, the problem we are having is that we can't debug it, and we only have partial information. Please link to a test case showing the issue so we can help.

    Allan

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited December 2023

    I haven't used JSONP but as I mentioned earlier I think the problem is your server script is not supporting JSONP. Based on all the JSON responses you've posted it doesn't look like they are JSONP responses. Use the browser's network inspector with this example. and you will see the request and response are wrapping the data in a function like this jQuery37007004015063149109_1702421439731({ ... }).

    This example sends the request with dataType: 'jsonp' but the response is a standard JSON response with the `Invalid JSON response error as the result:
    https://live.datatables.net/dodobuge/52/edit

    Use the browser's network inspector and you will see the request has a query string similar to this:

    callback: jQuery363046249296824125374_1702515455731
    _: 1702515455732
    

    It expects the response to contain the function, like this:

     jQuery363046249296824125374_1702515455731({ ... })
    

    But the response is a standard JSON response, like yours, and causes the Invalid JSON response error.

    This is the same example with dataType: 'jsonp' commented out and it works.
    https://live.datatables.net/bedufoso/1/edit

    Based on this it is my opinion that you either need to enable JSONP in your server script or remove dataType: 'jsonp' from the ajax option.

    As Allan said for us to help further please post a link to your page or a test case replicating the error so we can help debug.

    Kevin

Sign In or Register to comment.