Получите данные JSON из Bing Search API в JavaScript

Я пытаюсь вернуть данные json с помощью API поиска Bing и отображаю их. Возвращенный результат json имеет вид:

{"d":{"results":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/News?Query=\u0027britain\u0027&$skip=0&$top=1","type":"NewsResult"},"ID":"38eda3ba-9e50-4d48-9fd1-bde42b743966","Title":"Britain\u0027s Prince William and Kate try archery in Bhutan","Url":"http://timesofindia.indiatimes.com/world/south-asia/Britains-Prince-William-and-Kate-try-archery-in-Bhutan/articleshow/51835828.cms","Source":"Times of India","Description":"Britain\u0027s Catherine looks on as she watches Prince William prepare to fire an arrow at an archery ground in Th... Read More THIMPHU: Britain\u0027s Prince William and his wife Kate tried their hand at Bhutan\u0027s national sport of archery on Thursday as they began ...","Date":"2016-04-15T08:30:00Z"}],"__next":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/News?Query=\u0027britain\u0027&$skip=15"}}

То, что я пытался сделать, это

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>

<script src="jquery-1.12.3.js">

$(document).ready(function() {

  var appId = ':MyKeyHere';

  function getNews() {
    var azureKey = btoa(appId);
    var myUrl = 'https://api.datamarket.azure.com/Bing/Search/v1/News?Query=%27britain%27&$format=json';

    $.ajax({
      method: 'post',
      url: myUrl,
      dataType:"json"

      //Set headers to authorize search with Bing
      headers: {
        'Authorization': 'Basic ' + azureKey
      },
      success: function(data) {
       var json = data.d.results[0].Title;    
       document.getElementById("demo").innerHTML = json;
      },
      failure: function(err) {
        console.error(err);  
      }
    });
  };

  getNews();

});
</script>
</body>
</html>

Кто-нибудь может сказать мне, что я делаю не так? Я новичок в этом. Итак, несколько вопросов:

  1. Содержит ли переменная данных объект json или содержит строку json, и мне нужно ее проанализировать?

  2. Я не получаю ни вывода, ни ошибок. Что мне не хватает?

0 ответов

Другие вопросы по тегам