S
S
SvetlanaDubovik2017-10-21 12:19:23
JavaScript
SvetlanaDubovik, 2017-10-21 12:19:23

Can't read local json file. What's wrong?

Hello. I'm trying to run an example for twitter typeahead.

<script type="text/javascript">
$(document).ready(function(){
    // Sonstructs the suggestion engine
    var countries = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.whitespace,
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        // The url points to a json file that contains an array of country names
        prefetch: '/test/countries.json'
    });
    
    // Initializing the typeahead with remote dataset
    $('.typeahead').typeahead(null, {
        name: 'countries',
        source: countries,
        limit: 10 /* Specify maximum number of suggestions to be displayed */
    });
});  
</script>
</head>
<body>
    <div class="bs-example">
    <h2>Enter your country name</h2>
        <input type="text" class="typeahead tt-query" autocomplete="off" spellcheck="false">
    </div>
</body>


But this example doesn't work for me. If you try to find 192.168.0.103/test/countries.json in the browser, it finds it, but the script does not work. What's wrong? I use xampp as a server

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question