Getting "4. Warning: Requested unknown parameter" with simple JSON/AJAX load.

Getting "4. Warning: Requested unknown parameter" with simple JSON/AJAX load.

Destin H.Destin H. Posts: 6Questions: 1Answers: 0

I'm having some difficulty getting something very simple to load using the ajax option. I've tried a variety of different solutions, involving both modifying my AJAX as well as my JavaScript, and nothing seems to be working. My JSON is valid, and follows the pattern shown here:

Just as a test, I'd simply like this table:


To display the value in "location" from each element inside of "data."

My JavaScript looks like this:

I always get this warning:

And nothing displays inside the table. Is there something I'm missing?

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Is example_json.json served by a webserver or a local file? It won't work as a local files as Ajax is sending an XMLHttpRequest to the server.

    If you are using a webserver then follow the troubleshooting steps in this tech note to see the actual response from the server.

    You might want to look at the Nested Objects example if you want to display the weekly_data object under the days of the week.

    Kevin

  • Destin H.Destin H. Posts: 6Questions: 1Answers: 0

    I've tried using both the webserver that is supplying the json, as well as a local file, but both result in the same issue. The webserver differs slightly from the screenshot I provided, the json being formatted like a flat array:

    I updated my JS according to this part of the documentation in order to use this json, but the same issue still persists.

    As for the troubleshooting steps, the response is normal and the json is valid.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Unfortunately your screenshots aren't enough to help. The best option would be to provide a link to your page so we can take a look. If you can't do that then start with collecting debugger information and post the resulting link.

    Kevin

  • Destin H.Destin H. Posts: 6Questions: 1Answers: 0

    Thank you for the quick response, here's my debug code:

    uyazic

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947
    edited February 2019

    I was noticing something in your waring message that you posted. It says Requested unknown parameter '0'..... This means that it is looking for an array of data but since you are using columns.data it should actually say something like Requested unknown parameter 'location'.....

    Then I notice that it lists table id DataTables_Table_0. But your screenshot of the table just shows the table defined with the class hour-table. Seems like your jQuery selector of $(".hours-table") is finding a table you aren't expecting.

    Kevin

  • Destin H.Destin H. Posts: 6Questions: 1Answers: 0

    Think that might be unrelated. I switched over to using an id to get my table

    <table id="hours-table">
    

    and

    let table = $("#hours-table").DataTable
    

    but the warning is still the same:

    I'm definitely getting the right table, as the table on the page is getting turned into a datatables table, with features like searching, pagination, ect. Could the warning be showing Requested unknown parameter '0' because it can't find the 0th element in the json array?

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947
    edited February 2019

    Tried to open the link to the debug code:
    https://debug.datatables.net/uyazic

    I receive a 404 error. Did you delete the debug output?

    EDIT: Sorry didn't realize some changes in the debugger privacy have taken place. Now only employees are able to look at the debugger output. Either @allan or @colin will need to take a look.

    Kevin

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    It still seems odd you are getting Requested unknown parameter '0' since you are using columns.data. According to the tech note link (https://datatables.net/manual/tech-notes/4):

    When {parameter} is an integer, DataTables is looking for data from an array. This is usually the case when using DOM sourced data

    Please post a couple rows, as text, of the JSON response, by copying the text from the Developer Tools > Network > Response tab. These are from Chrome the exact steps might be different in other browsers.

    Kevin

  • Destin H.Destin H. Posts: 6Questions: 1Answers: 0

    Recreated my project from the ground up, and the only difference is that instead of

    "columns:": 
    [
        { "data": "location" },
        { "data": "location" },
        { "data": "location" }
    ]
    

    I have

    "columns": 
    [
        { 
            "data": 
            {
                location: "location",
            },
            "render": function(data, type, row, meta) 
            {
                return data.location;
            } 
        },
        { 
            "data": 
            {
                location: "location",
            },
            "render": function(data, type, row, meta) 
            {
                return data.location;
            } 
        },
        { 
            "data": 
            {
                location: "location",
            },
            "render": function(data, type, row, meta) 
            {
                return data.location;
            } 
        },
    ]
    

    I did this mimicking another project I had worked on a few months ago where the render function was needed, and the project was working just fine. I can't tell you if this change fixed my issues or if there was something hidden away that I was missing, but as far as I'm aware this is the only difference, and everything is now working as expected.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Seems strange you would have to do that. If you want help to get it working with this:

    "columns:":
    [
        { "data": "location" },
        { "data": "location" },
        { "data": "location" }
    ]
    

    then please follow the steps above to provide the JSON response from your browser.

    Kevin

  • Destin H.Destin H. Posts: 6Questions: 1Answers: 0

    Changed back to using { "data": "location" } and everything is still working fine. Clearly I must have had something broken somewhere else or some sort of typo. Apologies for the waste of time.

This discussion has been closed.