0
イムioのソケットに外部サーバ(API)に接続し、私のエラーを与えている:カントは、APIのみに接続しようとしているが、動作していない
XMLHttpRequest cannot load https://api.sports/socket.io/?api_key=aredasdasdadds&EIO=3&transport=polling&t=LsYSPsv. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 596.
奇妙なことは、エラー上映中です別のAPI URL。
私のコードは次のとおりです。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Web socket</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script type="text/javascript">
// Create SocketIO instance, connect
var socket = new io('https://api.sports.com/soccer-/eu/en/matches/summary.json?api_key=aredasdasdadds');
socket.connect();
// Add a connect listener
socket.on('connect',function() {
console.log('Client has connected to the server!');
});
// Add a connect listener
socket.on('message',function(data) {
console.log('Received a message from the server!',data);
});
// Sends a message to the server via sockets
function sendMessageToServer(message) {
socket.send(message);
}
</script>
</body>
</html>
このURLは、Socket.IOエンドポイントのようには見えません。あなたはそのURLを_retrieve_しようとしていますか?その場合は、['fetch'](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)を使用してください。 – robertklep