Qual: add cache in autocompleter for minimize the request
This commit is contained in:
parent
05db777d77
commit
668bc945dd
@ -88,9 +88,20 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
|
|||||||
|
|
||||||
$script.= '<script type="text/javascript">';
|
$script.= '<script type="text/javascript">';
|
||||||
$script.= 'jQuery(document).ready(function() {
|
$script.= 'jQuery(document).ready(function() {
|
||||||
|
var cache = {};
|
||||||
jQuery("input#search_'.$htmlname.'").autocomplete({
|
jQuery("input#search_'.$htmlname.'").autocomplete({
|
||||||
source: function( request, response ) {
|
source: function( request, response ) {
|
||||||
|
if (cache.term == request.term && cache.content) {
|
||||||
|
response(cache.content);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
|
||||||
|
response($.ui.autocomplete.filter(cache.content, request.term));
|
||||||
|
return;
|
||||||
|
}
|
||||||
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
|
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
|
||||||
|
cache.term = request.term;
|
||||||
|
cache.content = data;
|
||||||
response( jQuery.map( data, function( item ) {
|
response( jQuery.map( data, function( item ) {
|
||||||
if (data.length == 1) {
|
if (data.length == 1) {
|
||||||
jQuery("#search_'.$htmlname.'").val(item.value);
|
jQuery("#search_'.$htmlname.'").val(item.value);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user