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.
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
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
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
When using server side processing each
draw()
orajax.reload()
will use theajax
option definition in the Datatables init code. Each ajex request wil send the parameters documented here. You also haveajax.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:
ajax.data
parameters.The 404 error is a server error so all troubleshooting will need to happen at the web server.
Kevin