无法在淘汰赛中使用getJSON方法获取JSON数据

时间:2018-11-27 10:02:27

标签: knockout.js

我正在尝试在淘汰表js中使用$ .getJSON方法,但是出现Uncaught (in promise) ReferenceError: $ is not defined错误。我正在为此项目使用剔除3.4.2.js。

这是我的JavaScript代码:

// get JSON request of foursquare data
    var reqURL = 'https://api.foursquare.com/v2/venues/search?ll=' + this.position.lat + ',' + this.position.lng + '&client_id=' + clientID + '&client_secret=' + clientSecret + '&v=20160118' + '&query=' + this.title;
    console.log(reqURL);
    $.getJSON(reqURL).done(function(data) {
        var results = data.response.venues[0];
        self.street = results.location.formattedAddress[0] ? results.location.formattedAddress[0] : 'N/A';
        self.city = results.location.formattedAddress[1] ? results.location.formattedAddress[1] : 'N/A';
        self.phone = results.contact.formattedPhone ? results.contact.formattedPhone : 'N/A';
    }).fail(function() {
        alert('Something went wrong with foursquare');
    });

HTML:

<body>
        <nav class="navbar navbar-light bg-light">
            <!-- <form class="form-inline"> -->
                <div class="input-group">
                    <input type="text" class="form-control mr-sm-2" placeholder="Search" name="q" data-bind="textInput: searchItem, valueUpdate: 'afterkeydown'">
                    <!-- <div class="input-group-btn">
                        <button class="btn btn-outline-success my-2 my-sm-0"><i class="glyphicon glyphicon-search"></i></button>
                    </div> -->
                </div>
            <!-- </form> -->
        </nav>
        <div class="container">
            <div class="col-lg-5">
                <div class="list-group" data-bind="foreach: locationList">
                    <a href="#" class="list-group-item list-group-item-action" data-bind="text: title, click: show"></a>
                </div>
            </div>
            <div id="map"></div>
        </div>
        <!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> -->

        <script type="text/javascript" src="js/knockout-3.4.2.js"></script>
        <script src="js/data.js"></script>
        <script type="text/javascript" src="js/test.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCzvsr0e94zenMFlGePE-ywIdt4VoUEy7c&callback=initMap" async defer></script>
    </body>

请帮助我克服此错误。

1 个答案:

答案 0 :(得分:0)

$是jQuery,因此请检查是否包含jQuery javascript文件。