This is a simple solution for this in the jQuery UI Autocomplete documentation . There you will find a section called Remote with caching , which shows how to implement what you are looking for.
I adapted the code from this site to this question and added comments for clarification:
var cache = {}; $( "#country" ).autocomplete({ source: function( request, response ) {
As I did not know the exaclty JSON format, I just used the base one, which for the returned text is "In": ["India","Indonesia","Spain"] (without ids, just a simple array).
If you are using the Ajax AutoComplete plugin for jQuery (this code looks like the question was tagged with jquery-ui-autocomplete ), then you do not need to worry about caching because the plugin does this automatically for you .
From the plugin documentation:
noCache : A Boolean value indicating whether to indicate the results of a cache request. The default is false .
Since you did not specify any value for noCache , then it will default to false and it will cache directly.
source share