Ajax Request Flooding
Ajax Request Flooding
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.
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.
This discussion has been closed.
Replies
Allan
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.
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