Ajax request failing with more than 8 data columns
Ajax request failing with more than 8 data columns
This is my code.
$('#remote').DataTable({
"iDisplayLength": 1,
"searching": false,
"ordering": false,
"ajax": {
"url": API_host + '/api/Report/RiskyDrivers',
"dataSrc": function(json){
json.recordsTotal = json.TotalRecordCount;
json.recordsFiltered = json.QueryRecordCount;
return json.Data.DriversList;
},
"crossDomain": true,
"beforeSend": function(xhr) {
xhr.setRequestHeader('Authorization', 'bearer ' + API_token);
},
"contentType": 'application/json',
"dataType": 'json'
},
"columns": [
{"data": "Id"},
{"data": "DriverName"},
{"data": "TotalInfractions"},
{"data": "TotalBackingUpWhenLeavingInfractions"},
{"data": "TotalHardAccelerationInfractions"},
{"data": "TotalHarshBrakingInfractions"},
{"data": "TotalHarshCorneringInfractions"},
{"data": "TotalSeatbeltInfractions"}
// {"data": "TotalSpeedingInfractions"}
// {"data": "TotalExceptions"}
// {"data": "TotalBackingUpWhenLeavingExceptions"},
// {"data": "TotalHardAccelerationExceptions"},
// {"data": "TotalHarshBrakingExceptions"},
// {"data": "TotalHarshCorneringExceptions"},
// {"data": "TotalSeatbeltExceptions"},
// {"data": "TotalSpeedingExceptions"}
],
"processing": true,
"serverSide": true
});
As soon as I uncomment one more data attribute, the request fails. Well the reason i found is the query string crosses 2k characters, as I add further data columns, which most modern browsers don't allow. How to overcome this?! This seems to be a major problem. Any help would be great.
P.S You wont be able to call the above service since the servers have our origin added in their headers. I am getting the data. I need server-side pagination that's why I have enabled serverSide to be true. So the client sends a whole bunch of query parametres! My request becomes a gigantic THIS!:
This question has an accepted answers - jump to answer
Answers
Ajax Request failing for more than 8 data columns. throws 400 Bad request if one single column data is added more.
You are hitting a request limit for your HTTP server. I would suggest you use POST data.
If you do a forum search you'll find a number of other discussions on this topic as well.
Allan
Can you link me to one which matches mine?
And if u use POST then how can I get the return data? The API is RESTful and this request should be a GET one.
I wasn't aware of that requirement. If you can't make a POST request, then you need to do one of:
ajax.data
to remove some of the parameters DataTables is sending to the server that you don't need (perhaps you don't need the column information for example - I don't know).Allan