Bing Azure Search API使用AJAX

时间:2015-02-27 00:49:20

标签: jquery ajax bing-api

我正在学习如何向Bing Azure Search API发出AJAX请求,我已经注册了该帐户并检索了一个密钥,但我一直在ajax回调上遇到错误。

var key = 'aaaaaaaaaaaaaaaaaaaaa';
var searchURL = 'https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=web&Query=';

$('input').on('keyup', function (evt) {

        getResults($(this).val());

});

function getResults(query) {
    var q = query;
    var url = encodeURI(searchURL + q );

    $.ajax({
        url: url,
        dataType: 'jsonp',
    }).done(function(response){
        alert(response);

    });
}

这是我的HTML:

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
    </head>
    <body>
        <div class="search-bar">
            <input type="text" placeholder="search for anything...">
        </div>

        <script src="main.js"></script>
    </body>
</html>

0 个答案:

没有答案