draw is unnecessary in server side processing

draw is unnecessary in server side processing

mitarmitar Posts: 4Questions: 2Answers: 0

Passing draw to the sever is unnecessary in server side processing. The following works equally well for its purpose (handling asynchronous nature of requests), but does not require server to echo anything back (potentially a security issue) and does not break caching: with current "draw" parameter, it is impossible to cache requests because each request is different URL. This is really bad.

(Sorry that code is for older version of dataStream.)

                'fnServerData': function (sSource, aoData, fnCallback, oSettings) {
                    // Instead of passing sEcho to the server and breaking caching, we set
                    // it in JavaScript, which still makes clear to dataTables which request
                    // is returning and when, but does not modify HTTP request
                    var echo = null;
                    for (var i = 0; i < aoData.length; i++) {
                        switch (aoData[i].name) {
                            case 'sEcho':
                                echo = aoData[i].value;
                                aoData.splice(i, 1);
                                i--;
                                break;
                            default:
                                break;
                        }
                    }
                    $.fn.dataTable.defaults.fnServerData(sSource, aoData, function (json) {
                        json.sEcho = echo;
                        fnCallback(json);
                    }, oSettings);
                },
This discussion has been closed.