预测 API 数据访问 [英] Forecast API data access

查看:11
本文介绍了预测 API 数据访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何访问以下数据?目前我只想玩弄数据,以便我可以更好地了解它是如何运作的.我以前从未使用过 API,但我熟悉 JSON 的概念.

How can I access the following data? At the moment I only want to play around with data so that I can better understand how it all works. I have never worked with APIs before, however I am familiar with the concept of JSON.

 $.getJSON( "https://api.forecast.io/forecast/APIKEY/40.463487,17.248535", function( data ) {
    console.log('here');
    console.log(data);
 });

我在我的本地尝试过这个,它返回:XMLHttpRequest 无法加载 https://api.forecast.io/forecast/APIKEY/40.463487,17.248535.Access-Control-Allow-Origin 不允许 Origin http://weathercast.com.

I have tried this on my local and it returns: XMLHttpRequest cannot load https://api.forecast.io/forecast/APIKEY/40.463487,17.248535. Origin http://weathercast.com is not allowed by Access-Control-Allow-Origin.

我只需要数据.

推荐答案

你不能做跨域的AJAX查询,

you can't do cross-domain AJAX query,

如果你想解决这个问题,你可以使用JSONP:

if you want to resolve this, you can use JSONP:

$.ajax({
  url: "https://api.forecast.io/forecast/APIKEY/40.463487,17.248535",
  dataType: "jsonp",
  success: function (data) {
      console.log('here');
      console.log(data);
  }
});

这篇关于预测 API 数据访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆