我的原子防火墙将我的自动完成脚本标记为 DDOS 攻击我进入了 jquery 自动完成脚本并对其进行了更改,因此它 1)仅查找 3 个字母然后创建一个列表 2)仅在未发送查询时进行查询 这可能不是最好的方法,但它阻止了所有的防火墙问题,并降低了我的服务器负载,不会发出高负载警告,可能会减少 80%
function request(term, success, failure) {
if (!options.matchCase)
term = term.toLowerCase();
var data = cache.load(term);
// recieve the cached data
if (data && data.length) {
success(term, data);
// if an AJAX url has been supplied, try loading the data now
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
var extraParams = {
timestamp: +new Date()
};
$.each(options.extraParams, function(key, param) {
extraParams[key] = typeof param == "function" ? param() : param;
});
// added by gary - the ajax call is made at 3 letters and only 1 call is made to avoid swamping the server with ajax requests
if(term.length>'3'){
stopLoading();
}
if(term.length=='3'){ // added by gary
var calls=$("#AUTOCOMPLETECALLS").val();
if(calls==0){ //by pass if a call already made
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
data: $.extend({
q: lastWord(term),
limit: options.max
}, extraParams),
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
var numCalls=$("#AUTOCOMPLETECALLS").val();
numCalls++;
$("#AUTOCOMPLETECALLS").val(numCalls);
var idData = $(input).attr('id');
if(idData=='txtText'){
var SplitData=data.split("|");
if(SplitData[1]==undefined){
if(document.getElementById('donor_id') != null)
{
$("#donor_id").val('0');
$("#NewRecepientWarning").show();
}
} }
}
});
} // eof calls
} else { //eof term.length
// no match is selected the user just keeps typing
hideResultsNow();
var idData = $(input).attr('id');
if(idData=='txtText'){
if(document.getElementById('donor_id') != null)
{
$("#donor_id").val('0');
$("#NewRecepientWarning").show();
} }
}
} else {
// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
select.emptyList();
failure(term);
}
};