POST also forces a new GET after the changes GET?

POST also forces a new GET after the changes GET?

jorgelaranjojorgelaranjo Posts: 5Questions: 2Answers: 0
edited March 2022 in Free community support

I have an HTML with Datatables and Datables Editor in it.
The Editor is set to POST URL /ajax/endpoint/{id} and that works.
On the backedn the update takes place and then the object changed is returned as
{data:[{ .... }]}

Datatables runs a GET to /ajax/endpoint/

The backend checks if the request is GET or POST and responds with the result of a database select or the result of the change (in the case of edit).

When testing, after the POST the response gets generated, with the change executed (as per documentation server/client).

Just after that a new GET gets generated to the /ajax/endpoint/ which I assume is done by the Datatable component.

Is this the normal behavior, and if so what is the first return for?

Backend is Python thus looking at docs here: https://editor.datatables.net/manual/server#Server-to-client

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Sounds like you are using draw() or ajax.reload() in an event that occurs after the Editor update response. Using one of these APIs will cause the additional GET request from Datatables. As an example look at lines 94-112 of this example. It has events using ajax.reload(). Look for something like this in your code.

    If you still need help please post your relevant Editor and Datatables code. Better would be a link to your page or running test case showing the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • jorgelaranjojorgelaranjo Posts: 5Questions: 2Answers: 0

    I don't have those API as far as I can tell.

    <script>
        var editor; 
    
        $(document).ready(function () {
        editor = new $.fn.dataTable.Editor( {
    (...)
    
        $('#table').DataTable({
                "processing": true,
                "serverSide": true,
                "ajax": "/ajax/endpoint",
    (...)
    </script>
    
    

    I believe the cause is the serverSide setting?

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    Yes, I believe you are correct. After the Editor updates the table Datatables wants to refresh the table to update sorting, searching, etc. This causes Datatables to fetch the page data from the server.

    Kevin

Sign In or Register to comment.