File tree Expand file tree Collapse file tree 1 file changed +8
-25
lines changed
Expand file tree Collapse file tree 1 file changed +8
-25
lines changed Original file line number Diff line number Diff line change 1212 < link type ="text/css " href ="../demos.css " rel ="stylesheet " />
1313 < script type ="text/javascript ">
1414 $ ( function ( ) {
15- function log ( message ) {
16- $ ( "<div/>" ) . text ( message ) . prependTo ( "#log" ) ;
17- $ ( "#log" ) . attr ( "scrollTop" , 0 ) ;
18- }
19-
2015 var cache = { } ;
21- $ ( "#birds" ) . autocomplete ( {
16+ $ ( "#birds" ) . autocomplete ( {
17+ minLength : 2 ,
2218 source : function ( request , response ) {
23- if ( cache . term == request . term && cache . content ) {
24- response ( cache . content ) ;
25- return ;
26- }
27- if ( new RegExp ( cache . term ) . test ( request . term ) && cache . content && cache . content . length < 13 ) {
28- response ( $ . ui . autocomplete . filter ( cache . content , request . term ) ) ;
19+ if ( request . term in cache ) {
20+ response ( cache [ request . term ] ) ;
2921 return ;
3022 }
23+
3124 $ . ajax ( {
3225 url : "search.php" ,
3326 dataType : "json" ,
3427 data : request ,
35- success : function ( data ) {
36- cache . term = request . term ;
37- cache . content = data ;
38- response ( data ) ;
28+ success : function ( data ) {
29+ cache [ request . term ] = data ;
30+ response ( data ) ;
3931 }
4032 } ) ;
41- } ,
42- minLength : 2 ,
43- select : function ( event , ui ) {
44- log ( ui . item ? ( "Selected: " + ui . item . value + " aka " + ui . item . id ) : "Nothing selected, input was " + this . value ) ;
4533 }
4634 } ) ;
4735 } ) ;
5644 < input id ="birds " />
5745</ div >
5846
59- < div class ="ui-widget " style ="margin-top:2em; font-family:Arial ">
60- Result:
61- < div id ="log " style ="height: 200px; width: 300px; overflow: auto; " class ="ui-widget-content "> </ div >
62- </ div >
63-
6447</ div > <!-- End demo -->
6548
6649< div class ="demo-description ">
You can’t perform that action at this time.
0 commit comments