Ajax Request Flooding

Ajax Request Flooding

hawxhawx Posts: 1Questions: 0Answers: 0
edited June 2011 in General
Hi,

First, just like to say I'm loving the datatable. Only one minor prob which I can quiet figure out.

Is there a way to configure so that the global search and filter searches only perform a search on key press e.g enter button?

I need this because my ajax file keeps getting ddos'd by the look of it. There is a php security check on the first line and its keeps logging me out my application.

Any ideas or direction will be much appriciated.

Gaf.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    There is a plug-in for exactly that: http://datatables.net/plug-ins/api#fnFilterOnReturn - or there is a timeout version: http://datatables.net/plug-ins/api#fnSetFilteringDelay .

    Allan
  • hawxhawx Posts: 1Questions: 0Answers: 0
    Hi Allan, thanks for the response and both your suggestion work absolutely fine. The only problem is that I am using row sorting and individual column filtering(jquery.dataTables.columnFilter.js) and therefore the problems still persists when I use them features.

    I have show my code below.

    [code]







    jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
    var

    _that = this,

    iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;



    this.each( function ( i ) {

    $.fn.dataTableExt.iApiIndex = i;

    var

    $this = this,

    oTimerId = null,

    sPreviousSearch = null,

    anControl = $( 'input', _that.fnSettings().aanFeatures.f );



    anControl.unbind( 'keyup' ).bind( 'keyup', function() {

    var $$this = $this;



    if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {

    window.clearTimeout(oTimerId);

    sPreviousSearch = anControl.val();

    oTimerId = window.setTimeout(function() {

    $.fn.dataTableExt.iApiIndex = i;

    _that.fnFilter( anControl.val() );

    }, iDelay);

    }

    });



    return this;

    } );

    return this;

    }





    $(document).ready(function() {





    var oTable = $('#example').dataTable( {

    "oLanguage": { "sSearch": "Search all columns:"},

    "aoColumns": [{ "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center" },

    { "sClass": "center", "bSortable": false }],

    "bProcessing": true,

    "bServerSide": true,

    "sAjaxSource": "service_calls_ajax.php",

    "bJQueryUI": true,

    "sPaginationType": "full_numbers",

    "iDisplayLength": 20,

    "aLengthMenu": [[20, 50, 100, 500, -1], [20, 50, 100, 500, "All"]],

    "aaSorting": [[0,'desc']],

    "fnDrawCallback": function() {

    $(".colorbox").colorbox({width:"730px", height:"100%", iframe:true});

    }

    }).fnSetFilteringDelay(1500)

    .columnFilter({

    aoColumns: [

    { type: "text" }, { type: "text" }, { type: "text" }, { type: "text" }, { type: "text" }, { type: "text" },

    { type: "select", values: ['Closed', 'Duplicate', 'In Progress', 'Pending', 'Finished'] },

    { type: "select", values: ['OX5 1NY', 'SN3 5EY', 'ML14YQ', 'IP286TS', 'RG2 9NH', '14.South Coast', '12.M4 Corridor', '11.West Country', 'Duplicate', '02.Scotland-North', '04.North East', '07.Leeds (M1)', '08.Wales', '03.Scotland-South', '06.Manchester (M6)', '10.East Anglia', '13.London Area', '15.Kent', '09.Midlands', ''] }, { type: "text" }, null ]

    });;

    });



    $('#example tr').live('click', function () {

    if ( $(this).hasClass('row_selected') )

    $(this).removeClass('row_selected');

    else

    $(this).addClass('row_selected');

    } );



    [/code]

    Would it be possible to somehow modify the fnSetFilteringDelay to include the row sorting and filtering requests as well.

    I have spent hours on this problem before deciding to bug you again. Your help would be great help,

    Thanks in advance.

    Gaf.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    fnSetFilteringDelay is very specifically designed for the filtering options of DataTables since that is the one which is most likely to change rapidly. However, there is no reason why similar plug-ins should be created for sorting etc.

    A more robust solution would be to use fnServerData ( http://datatables.net/ref#fnServerData ) - you could create something similar to the technique used in the filtering delay plug-in to delay the server request and then only do the request after a set amount of time. This would then work across all DataTables features (and remove the need for the filtering delay plug-in).

    Allan
This discussion has been closed.