AJAX Autocomplete Example - Autocomplete Caching
Now we are talking mostly in Javascript.
AJAX data returns both id and value now. In original script the Option ID will be hidden, presently showing for tutorial purpose.
The returned data from the AJAX Call is stored locally and further typed text first searches locally. If no match is found locally then another AJAX call is made.
The 1st ajax call will return a large number of data. Typing further will result in words which are subset of the returned data (remember you can type while the AJAX call is active). Once the typed text does not match any local data then we have a long text to search for thus refining our result. The process continues again with another AJAX call with better result each time. The script assumes that after so many data if still you do not get the expected result then the database does not have expected result and stops making more than 4 AJAX Calls by setting Javascript Variable "nothing" to false.
Once there is no data to show, then the typed text only shows in the option.
AJAX data returns both id and value now. In original script the Option ID will be hidden, presently showing for tutorial purpose.
The returned data from the AJAX Call is stored locally and further typed text first searches locally. If no match is found locally then another AJAX call is made.
The 1st ajax call will return a large number of data. Typing further will result in words which are subset of the returned data (remember you can type while the AJAX call is active). Once the typed text does not match any local data then we have a long text to search for thus refining our result. The process continues again with another AJAX call with better result each time. The script assumes that after so many data if still you do not get the expected result then the database does not have expected result and stops making more than 4 AJAX Calls by setting Javascript Variable "nothing" to false.
Once there is no data to show, then the typed text only shows in the option.
AJAX Autocomplete Examples to be read along with AJAX Autocomplete Tutorial