Reputation: 291
I can't get the prefetch function in typeahead.js to work, it works just fine with the local data though. I first tried linking to a servlet returning json objects or lists, but after a while I gave up on that and started checking the provided examples. So their examples links to pages that look like this: http://twitter.github.io/typeahead.js/data/countries.json However, my script doesn't even work when I link it to that page even if I do exactly the same thing as they do. I tried copying that file over to my local workspace and linking to it there to no avail. To check if it even were making any calls I made my servlet crash every time it got a get request, and sure enough it crashed when I ran my autocomplete example page so it isn't a cache problem. I tried downgrading jquery to 1.9.1, but that didn't work either(currently using 1.10). I tried using different versions of typeahead.js. I tried using internet explorer as well as google chrome to see if the error was there.
There must be something vital that I am missing, as I have exhausted every source of errors I could think of. Others don't seem to have any problems getting this to work.
Here is the code I use:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo</title>
<link rel="stylesheet" type="text/css" href="typeahead.js-bootstrap.css">
</head>
<body>
<script src="jquery.js"></script>
<script src="typeahead.js"></script>
<input type="text" class="typeahead" placeholder="test" />
<script>
$(document).ready(function() {$('.typeahead').typeahead({
name: "Auto" ,
ttl_ms: 10000,
prefetch: 'http://twitter.github.io/typeahead.js/data/countries.json',
//local: ['abc', 'acd', 'ade', 'bcd]
});});
</script>
</body>
</html>
Upvotes: 3
Views: 6069
Reputation: 376
It seems the issue is related to caching of the data in the browser storage.
name
in typeahead config to another one.You can lower the ttl
in prefetch
. You can increase the ttl
later, of course. See below:
prefetch: {
url: 'http://twitter.github.io/typeahead.js/data/countries.json',
ttl: 1 // in milliseconds
},
It will be more clear if you browse the code here: http://goo.gl/TN3Gv
Upvotes: 10