Requested Unknown Parameter Warning for data that is seemingly there

Requested Unknown Parameter Warning for data that is seemingly there

profoundhypnoticprofoundhypnotic Posts: 12Questions: 5Answers: 0

Hello, I am getting the warning that Requested unknown parameter 'Name' for row 0. I can see in the network tab that the data is there in JSON format with the same column names as I have below in the code. I am trying to use Datatables in a success function of my ajax call. a screenshot of my data in network tab:

I'm sure I'm stupid and am missing something but any help is greatly appreciated

Script:

$('#filters').on('submit', function(e){
        e.preventDefault();
        $.ajax({
            type: 'post',
            url: 'test.php',
            data: $('#filters').serialize(),
            success: function(data){
                var tableData = data;
                $('#training').DataTable({
                    data: tableData,
                    columns: [
                        { data: 'Name' },
                        { data: 'func'},
                        { data: 'date'},
                        { data: 'score'}
                    ],
                });
            }
         });
    });

This question has an accepted answers - jump to answer

Answers

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

    It looks sensible enough. Could you:

    console.log( JSON.stringify( data ) );
    

    At the top of the success function and copy / paste the output from the console please?

    Thanks,
    Allan

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

    It could be the data is a JSON string not an object. You might need to use var tableData = JSON.parse( data ); to parse the response into a Javascript object.

    Kevin

  • profoundhypnoticprofoundhypnotic Posts: 12Questions: 5Answers: 0

    Thanks @kthorngren . I thought $.ajax returned JSON but after reading the documentation it's just a guess. Your suggestion worked. I also tried setting the datatype in the ajax call (dataType: 'json') and that worked as well. THANK YOU!

Sign In or Register to comment.