Ajax call on .draw() returns HTTP404 but same Ajax call works on page load and filtering.

Ajax call on .draw() returns HTTP404 but same Ajax call works on page load and filtering.

StuartStuart Posts: 3Questions: 1Answers: 0

Debugger code (debug.datatables.net): uxixaf
Error messages shown: DataTables warning: table id=facilitySearchResults - Ajax error. For more information about this error, please see http://datatables.net/tn/7
Description of problem:

I have a table configured with server side column filtering which works as expected. I've added a custom button to clear column filters and redraw the table. like such:

            "buttons": [{
                "text": "Reset",
                "className": "btn btn-primary",
                "action": function (e, dt, node, config) {
                    console.table(dt);
                    $("#facilitySearchResults th").each(function (i) {
                        var input = $(this).children().filter(":input");
                        var type = input.prop("type");
                        switch (type) {
                        case "text":
                            $(input).val("");
                            break;
                        case "select-one":
                            $(input).prop("selectedIndex", 14);
                            break;
                        }
                    });
                    dt.search("").columns().search("").order([0, "asc"]).draw();
                }
            }]
        },
        "ajax": {
            "url": routeUrl,
            "type": "GET",
            "dataType": "json",
            "data": function (d) {}
        },

The table loads, filters, pages, etc. as expected but when I click the "Reset" button the ajax call returns a HTTP404 not found error. The ajax call works just fine for loading, paging and sorting but when called with this method it gets a 404. The odd thing is that I've done this many times using the same button action. The 404 makes no sense as it uses the same ajax as the initial page load.

The xhr requests in the network tab look identical. I'm stumped. Has anyone ever experienced this?

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    The problem won't be with the client side Datatable. You will need to review the web server logs to determine why the server is returning 404 not found.

    Kevin

  • StuartStuart Posts: 3Questions: 1Answers: 0

    I suppose one thing I wanted to determine is whether or not the
    dt.search("").columns().search("").order([0, "asc"]).draw();
    was actually the same Ajax method as in the Datatables initialization as I assumed.

    Thanks

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    When using server side processing each draw() or ajax.reload() will use the ajax option definition in the Datatables init code. Each ajex request wil send the parameters documented here. You also have ajax.data as a function which looks to be empty. The additional data objects defined here will also be sent. You are using a GET request which will append all the parameters to the URL.

    Some possibilities I can think of:

    • Possibly you have a load balancer that routes traffic to a server that is misconfigured causing the 404 error.
    • Perhaps the web server "routes" you have configured fail with a particular combination of the sent server side processing parameters or ajax.data parameters.
    • Maybe the URL is too long using GET and you need to use POST for the data the be included in the payload instead of URL.

    The 404 error is a server error so all troubleshooting will need to happen at the web server.

    Kevin

Sign In or Register to comment.