I have an autocomplete implementation that is based mostly on this tutorial:
http://viralpatel.net/blogs/tutorial-create-autocomplete-feature-with-java-jsp-jquery
However as opposed to the article, I am getting the records from the Database and printing them out in the jsp with out.println(recordValue);
This jsp is called as:
<input type="text" id="country" name="country"/>
<script>
$("#country").autocomplete("getdata.jsp");
</script>
These records come out of a table containing millions of records so I am only putting top 10 records that I filter with “rowNum < 10;”
This works great for normal data. The problem comes when more than 10 records are returned by the query, and there could be more records…
For instance say I have data like:
Test10, Test11, Test12, Test13, Test14, Test15, Test16, Test17, Test18, Test19, Test20
Let’s say we make a query to fetch the records initially after typing Test, and that returned the 1st 10 records from Test10 to Test19 – which is correct.
But now when the user types Test2 we should query the back-end again, but that is not happening for me…
Like mentioned earlier, returning all the records is simply not an option, because there could be millions of records. But when there is a new character entered (like typing 2 after having typed Test), we need to reach back to the server inside the jsp that is called in the script above, for the getData to be called.
Is there any way to work around this issue?
I have already tried changing to this but it did not work
<input type="text" id="country" name="country"/>
<script>
$("#country").autocomplete({
change: "getdata.jsp"
});
</script>
Thanks!
Since I can’t add comments without 50 rep, editing the question to respond to @Barmar …
Thanks for your response @Barmar.
I did try by disabling cache in firefox and also in private mode so hopefully it won’t remember anything. But I am still seeing the same behavior
In order to debug further I added an alert in the jquery.autocomplete.js and it seems that that function does get called on key-down, but it still does not propagate the request to the server side on back-end. It seems the javascript is gobbling up the request, or there maybe some logic where it determines whether to send the request to the server. I am looking into this further.
However, what seems weird is a standard product like jquery could have issues, so maybe I am missing some setting/configuration. But I have not been able to figure out yet, what that could be.
Any help appreciated!
Found the solution to this problem.
The jQuery autocomplete javascript (the version we have) was caching the values returned by the 1st query, and would not go back to the back-end if any of the values in the cache matched the entered string.
Just started flushing the cache on keydown, and that resolved the problem.