首页 > 求教 用javascript请求百度API

求教 用javascript请求百度API

接口地址 :http://apis.baidu.com/txapi/d...
请求方法 :GET
请求参数(header) :
apikey: "您自己的APIkey"

这是百度一个API请求的格式要求
下面是我写的请求

function clickButton(){
  $.ajax({
    url: "http://apis.baidu.com/txapi/dictum/dictum",
    type:'GET',
    data: {
      header: {
        apikey:"847dc263c57e01777dae47dac857dd87"
      }    
    },
    success: function(response) {
      var r = JSON.parse(response);
      document.getElementById("quote-word").innerHTML=r.quote;
    }   
  });
};
'''

可是不知道为啥,请求就是不成功,求教各位。。
谢谢大家

function clickButton() {
  $.ajax({
    url: "http://apis.baidu.com/txapi/dictum/dictum",
    type: 'GET',
    headers: {
      'apikey': '847dc263c57e01777dae47dac857dd87'
    },
    success: function(response) {
      var r = JSON.parse(response);
      document.getElementById("quote-word").innerHTML=r.quote;
    },
    error: function(response) {
      alert(JSON.stringify(response));
    }
  });
}
【热门文章】
【热门文章】