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 12
12
< link type ="text/css " href ="../demos.css " rel ="stylesheet " />
13
13
< script type ="text/javascript ">
14
14
$ ( function ( ) {
15
- function log ( message ) {
16
- $ ( "<div/>" ) . text ( message ) . prependTo ( "#log" ) ;
17
- $ ( "#log" ) . attr ( "scrollTop" , 0 ) ;
18
- }
19
-
20
15
var cache = { } ;
21
- $ ( "#birds" ) . autocomplete ( {
16
+ $ ( "#birds" ) . autocomplete ( {
17
+ minLength : 2 ,
22
18
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 ] ) ;
29
21
return ;
30
22
}
23
+
31
24
$ . ajax ( {
32
25
url : "search.php" ,
33
26
dataType : "json" ,
34
27
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 ) ;
39
31
}
40
32
} ) ;
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 ) ;
45
33
}
46
34
} ) ;
47
35
} ) ;
56
44
< input id ="birds " />
57
45
</ div >
58
46
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
-
64
47
</ div > <!-- End demo -->
65
48
66
49
< div class ="demo-description ">
You can’t perform that action at this time.
0 commit comments