obnizのフォーラムは新しいシステムに移行しております。
新しいフォーラムはこちらになりますブラウザとイベントで外部API呼び出しの挙動が異なる
-
以下のコードで外部の天気APIを呼び出そうとしています。
$.ajax({
type: "GET",
scriptCharset: "utf-8",
dataType:"json",
url: "https://samples.openweathermap.org/data/2.5/forecast?id=524901&appid=b1b15e88fa797225412429c1c50c122a1",
}).done(function(data) {
console.log(data);
}).fail(function(xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
});このコードをブラウザから実行するとstatus = errorとなりJSONが取得できませんが、Cloudイベントとして実行するとJSONが取得できます。なぜ前者では取得できないのでしょうか?
ブラウザはChrome (mac), Safari, Firefoxで試してみましたが、いずれも結果はエラーでした。
-
自己解決しました。使用している天気APIサイト側がCORSに対応しておらず、ブラウザ内で以下のエラーが発生していました。
obniz_undefined_2018_8_27_10_10_55.html:1 Failed to load https://samples.openweathermap.org/data/2.5/forecast?id=524901&appid=b1b15e88fa797225412429c1c50c122a1: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
-
解決できたようでよかったです.
また何かありましたらお問い合わせください.
SUGGESTED TOPICS
-
obnizIDを入れたのに実行画面でNo new obniz foundと表示される
Question and Troubles • 2021年10月27日 8:15 • Fukushima701 2021年11月17日 7:46 -
UT-201BLEおよびUA-651BLEの値を読み出そうとするとObnizBleHciStateErrorが発生する
Question and Troubles • 2021年9月7日 6:49 • yuuu 2021年9月8日 2:28 -
M5StackBasicのButtonAのイベントを拾おうとしているのですが反応しません
Question and Troubles • 2021年9月5日 6:20 • 福井 暢宏 2021年9月5日 6:47 -
BLEデバイスに接続した場合に20秒ほど接続に時間がかかる
Question and Troubles • 2021年8月30日 4:49 • GDAS 2021年8月31日 1:37 -
Polar OH1 と connect後、Notifyの受信が無く、接続から15秒に disconnectします。
Question and Troubles • 2021年10月11日 2:58 • 常田文克 2021年10月21日 1:41