私が受けてるの誤差がある https://www.html5rocks.com/en/tutorials/cors/React/jQuery - なぜ 'Access-Control-Allow-Origin'ヘッダが拒否されていますか?
に(彼らは自分自身に従うことをお勧めしていること)CORSガイド以下のとき、私はまだ、このエラーを取得しています方法を理解するために自分のベストをやっている:
ロードに失敗しましたhttps://bittrex.com/api/v1.1/public/getmarketsummaries:要求されたリソースに 'Access-Control-Allow-Origin'ヘッダーがありません。 Origin 'http://localhost:3000'はアクセスできません。
これに基づいて、問題は$ .ajaxコールの内側にあると思いますか?
import React, { Component } from 'react';
import './App.css';
import $ from 'jquery';
export default class TokenList extends Component {
constructor(props) {
super(props);
this.state = {
object : []
};
}
componentDidMount() {
this.TokenList();
}
TokenList() {
// Method currently not working...
// Method 1
$.ajax({
type: 'GET',
url: 'https://bittrex.com/api/v1.1/public/getmarketsummaries',
contentType: 'text/plain',
xhrFields: {
withCredentials: false
},
success: function() {
console.log('Access Granted!');
},
// Error suggests the issue is here?
headers: {
'Access-Control-Allow-Origin' : 'http://localhost:3000'
},
error: function() {
alert('Error making the request');
}
})
}
そのURLは、応答に「Access-Control-Allow-Origin」ヘッダーを設定しません。あなたのAJAXリクエストはそれを設定できません。 –
可能duplicate https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present –
クロムには1つの拡張子があります。 localhostから外部URLを呼び出すのに役立ちます。https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi –