jsでapiからデータを取得したいのですが、
fetchで取得しようと試みてます。
Cross-Origin Read Blocking (CORB) blocked cross-origin
と警告が出て取得できません。
どう変更すれば取得できますか?
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <script> 7 let text = fetch('https://www.gaitameonline.com/rateaj/getrate', {mode: 'cors'}).then(onLoadFunc); 8 console.log(text) 9 </script> 10</head> 11<body> 12 test 13</body> 14</html>
取得したいのはリンク先のjson文字列です。
json
1{"quotes":[{"high":"1.9382","open":"1.9382","bid":"1.9382","currencyPairCode":"GBPNZD","ask":"1.9464","low":"1.9382"}, 2{"high":"83.47","open":"83.47","bid":"83.47","currencyPairCode":"CADJPY","ask":"83.67","low":"83.47"}, 3{"high":"1.8131","open":"1.8131","bid":"1.8131","currencyPairCode":"GBPAUD","ask":"1.8191","low":"1.8131"}, 4{"high":"79.93","open":"79.93","bid":"79.93","currencyPairCode":"AUDJPY","ask":"80.15","low":"79.93"}, 5{"high":"1.0674","open":"1.0674","bid":"1.0674","currencyPairCode":"AUDNZD","ask":"1.0722","low":"1.0674"}, 6{"high":"1.5041","open":"1.5041","bid":"1.5041","currencyPairCode":"EURCAD","ask":"1.5075","low":"1.5041"}, 7{"high":"1.1240","open":"1.1240","bid":"1.1240","currencyPairCode":"EURUSD","ask":"1.1250","low":"1.1240"}, 8{"high":"74.64","open":"74.64","bid":"74.64","currencyPairCode":"NZDJPY","ask":"74.94","low":"74.64"}, 9{"high":"1.3379","open":"1.3379","bid":"1.3379","currencyPairCode":"USDCAD","ask":"1.3403","low":"1.3379"}, 10{"high":"0.8644","open":"0.8644","bid":"0.8644","currencyPairCode":"EURGBP","ask":"0.8660","low":"0.8644"}, 11{"high":"1.2974","open":"1.2974","bid":"1.2974","currencyPairCode":"GBPUSD","ask":"1.2995","low":"1.2974"}, 12{"high":"7.877","open":"7.877","bid":"7.877","currencyPairCode":"ZARJPY","ask":"8.036","low":"7.877"}, 13{"high":"1.1394","open":"1.1394","bid":"1.1394","currencyPairCode":"EURCHF","ask":"1.1413","low":"1.1394"}, 14{"high":"110.17","open":"110.17","bid":"110.17","currencyPairCode":"CHFJPY","ask":"110.44","low":"110.17"}, 15{"high":"0.7144","open":"0.7144","bid":"0.7144","currencyPairCode":"AUDUSD","ask":"0.7161","low":"0.7144"}, 16{"high":"1.0134","open":"1.0134","bid":"1.0134","currencyPairCode":"USDCHF","ask":"1.0158","low":"1.0134"}, 17{"high":"125.73","open":"125.73","bid":"125.73","currencyPairCode":"EURJPY","ask":"125.94","low":"125.73"}, 18{"high":"1.3157","open":"1.3157","bid":"1.3157","currencyPairCode":"GBPCHF","ask":"1.3196","low":"1.3157"}, 19{"high":"1.6782","open":"1.6782","bid":"1.6782","currencyPairCode":"EURNZD","ask":"1.6849","low":"1.6782"}, 20{"high":"0.6671","open":"0.6671","bid":"0.6671","currencyPairCode":"NZDUSD","ask":"0.6695","low":"0.6671"}, 21{"high":"111.85","open":"111.85","bid":"111.85","currencyPairCode":"USDJPY","ask":"111.97","low":"111.85"}, 22{"high":"1.5699","open":"1.5699","bid":"1.5699","currencyPairCode":"EURAUD","ask":"1.5728","low":"1.5699"}, 23{"high":"0.7243","open":"0.7243","bid":"0.7243","currencyPairCode":"AUDCHF","ask":"0.7271","low":"0.7243"}, 24{"high":"145.17","open":"145.17","bid":"145.17","currencyPairCode":"GBPJPY","ask":"145.61","low":"145.17"}]}
回答1件
あなたの回答
tips
プレビュー