Ajax request specifying _ as the only query parameter?

Ajax request specifying _ as the only query parameter?

findoslicefindoslice Posts: 3Questions: 1Answers: 0

Hi, I'm sorry that this isn't a very fleshed out question, but when trying to set up data tables on a new project I'm encountering that instead of specifying the huge amount of query parameters an Ajax data table would, it just specifies _ as the only query parameter with a value of a random int. Is this a common issue? Is there some easy fix in the docs I'm missing? As far as I can tell, the table is configured correctly and the columns are correctly configured.

Answers

  • kthorngrenkthorngren Posts: 21,171Questions: 26Answers: 4,922

    Sounds like you have severSide processing enabled. If you do then it will send the parameters specified in the Server Side Processing docs for each request.

    You can use the ajax.data to send additional parameters.

    Hope this answers your questions.

    Kevin

  • findoslicefindoslice Posts: 3Questions: 1Answers: 0
    edited June 2020

    Thanks for your answer, I don't think that helps me though sadly. I do have serverSide enabled, but the issue that I'm having is that it isn't sending the parameters specific in the server side processing docs, instead the only query parameter it is sending is an _. i.e. /results/results/data_source/?_=1591009726466

    here is my code if that helps:

    $(data_table_elem).DataTable({
                serverSide: true,
                ajax: {
                    type: "GET",
                    url: "data_source/",
                    dataSrc: update_column_filters_from_ajax_data,
                },
                columns: JSON.parse($(data_table_elem)[0].dataset.columns),
                language: {
                    search: "",
                    searchPlaceholder: "Search",
                },
            });
    
  • kthorngrenkthorngren Posts: 21,171Questions: 26Answers: 4,922

    That looks like it should work. Not sure about the ajax.dataSrc though. Wouldn't expect your ajax.dataSrc to cause the problem you described but it may be problematic for server side processing to properly handle the response data. What is update_column_filters_from_ajax_data?

    Can you post a link to your page or a test case replicating the issue. This will allow us to help troubleshoot.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    I copied your code into this test case:
    http://live.datatables.net/mehobafe/1/edit

    Made a couple changes for it to work but you can see it send the server side parameters.

    Kevin

  • findoslicefindoslice Posts: 3Questions: 1Answers: 0

    This is the dataSrc function:

        const update_column_filters_from_ajax_data = (json) => {
            const api = $(".data-table").dataTable().api();
            const columns = api.settings().init().columns;
            api.columns().every(function (column_index) {
                if (this.allowFilter()) {
                    update_filters_for_column(this, json.distinct_column_values[columns[column_index].data]);
                }
            });
    
            return json.data;
        };
    

    I don't think it's this as the request is being made without query parameters so surely this would happen after the request and not affect it? I'll be able to post a test case later but I'm not currently able to.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    As Kevin said, please post a test case of link to your page.

    Colin

This discussion has been closed.