0

I've read all the official documentation, I've Googled, I've looked at the console there is no errors, but I can't get Twitter's typeahead.js to function at all.

I put up a test page here.

My actual source is:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Lookahead Test</title>
    <meta name="generator" content="BBEdit 9.6" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src='http://twitter.github.com/typeahead.js/releases/latest/typeahead.js'></script>
    <link rel='stylesheet' href='http://twitter.github.com/typeahead.js/releases/latest/typeahead.css' />
    </head>
<body>
<h1>This is a test of Twitter's typeahead.js</h1>
<div>
<form>
<input id="departure" type="text" placeholder="This appears when you load page">
</form>
</div>
<script>
$('#departure').typeahead({                                
  name: 'departure',                                                          
  prefetch: '/test.json',                                         
  limit: 10                                                                   
});
</script>

</body>
</html>

I only put three lines in the JSON file, it looks like this:

[
    "Vancouver, British Columbia, Canada (YVR)",
    "Calgary, Alberta, Canada (YYJ)",
    "Toronto, Lester B. Pearson International Airport, Ontario, Canada (YYZ)"
]

I originally had curly braces, but fixing that didn't make it go. I've looked at several working examples and I keep making changes to mine, but it never has worked. Do I need at least 10 pieces of data in my JSON file? Is the stylesheet mandatory?

Thanks in advance.

4

1 回答 1

0

我的 JSON 文件的路径不正确。我将它修改为绝对的,这使得 JavaScript 得以运行。

于 2013-06-10T22:18:01.443 回答