406当试图通过jQuery查询finance.yahoo.com/webservice(Yahoo Finance)时

时间:2016-06-27 12:12:44

标签: jquery json jsonp

我正试图通过Webservices从Yahoo Finance获取数据。我想查询这个来源。当我将它放入我的浏览器地址栏时,一切正常:

URL:

http://finance.yahoo.com/webservice/v1/symbols/DAI.DE,ALIK16.CMX/quote?format=json

结果:

{
  "list": {
    "meta": {
      "type": "resource-list",
      "start": 0,
      "count": 2
    },
    "resources": [
      {
        "resource": {
          "classname": "Quote",
          "fields": {
            "name": "DAIMLER N",
            "price": "54.439999",
            "symbol": "DAI.DE",
            "ts": "1467029449",
            "type": "equity",
            "utctime": "2016-06-27T12:10:49+0000",
            "volume": "3990557"
          }
        }
      },
      {
        "resource": {
          "classname": "Quote",
          "fields": {
            "name": "Aluminum Futures,May-2016",
            "price": "1600.250000",
            "symbol": "ALIK16.CMX",
            "ts": "1464022420",
            "type": "future",
            "utctime": "2016-05-23T16:53:40+0000",
            "volume": "3"
          }
        }
      }
    ]
  }
}

当我尝试在一个简单的HTML页面中实现这个qith jQuery时,我总是会收到错误406。我正在寻找几个小时没有任何解决方案。我做错了什么?

这是我的HTML页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Ohne_Titel_1</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">

$.ajax({
  url: "http://finance.yahoo.com/webservice/v1/symbols/DAI.DE,ALIK16.CMX/quote?format=json",
  dataType: 'jsonp',  //use jsonp data type in order to perform cross domain ajax
  crossDomain: true,
    success: function(json) {
    console.log(" reponse :"+ json);
    },error: function (XMLHttpRequest, textStatus, errorThrown) {
    console.log("error :"+XMLHttpRequest.responseText);
    }
});

</script>
</head>

<body>
    <div id='dvStockTicker' class='stockTicker'></div>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

这是一个老问题,但万一你偶然发现: 似乎雅虎改变了这个API的使用条款。似乎只允许从手机上使用,而不是从桌面上。 有关解决方法,请参阅:Has Yahoo finance web service disappeared? API changed? Down temporarily?