Ajax request failing with more than 8 data columns

Ajax request failing with more than 8 data columns

HaseebHaseeb Posts: 5Questions: 2Answers: 0

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!:

"https://rmj-api.azurewebsites.net/api/Report/RiskyDrivers?draw=1&columns%5B0%5D%5Bdata%5D=Id&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=DriverName&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=false&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=TotalInfractions&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=false&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=TotalBackingUpWhenLeavingInfractions&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=false&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=TotalHardAccelerationInfractions&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=false&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=TotalHarshBrakingInfractions&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=false&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=TotalHarshCorneringInfractions&columns%5B6%5D%5Bname%5D=&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=false&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=TotalSeatbeltInfractions&columns%5B7%5D%5Bname%5D=&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=false&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&start=0&length=1&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1468334291622''

This question has an accepted answers - jump to answer

Answers

  • HaseebHaseeb Posts: 5Questions: 2Answers: 0
    edited July 2016

    Ajax Request failing for more than 8 data columns. throws 400 Bad request if one single column data is added more.

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    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

  • HaseebHaseeb Posts: 5Questions: 2Answers: 0

    Can you link me to one which matches mine?

  • HaseebHaseeb Posts: 5Questions: 2Answers: 0

    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.

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    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:

    • Modify the HTTP server's settings to allow the query string to be longer
    • Use 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

This discussion has been closed.