Can';t使用getJSON从反人类卡api获取数据

Can';t使用getJSON从反人类卡api获取数据,json,reactjs,api,Json,Reactjs,Api,我使用了以下代码: import { Link, withRouter } from 'react-router-dom'; import { useState, useEffect } from 'react'; import $ from 'jquery'; export default withRouter(function Game() { const [pack, setPack] = useState(null); const [blackCards,setBlackCards]

我使用了以下代码:

import { Link, withRouter } from 'react-router-dom';
import { useState, useEffect } from 'react';
import $ from 'jquery';

export default withRouter(function Game() {
const [pack, setPack] = useState(null);
const [blackCards,setBlackCards] = useState([]);
const [whiteCards,setWhiteCards] = useState([]);

useEffect(function() {
    setPack(null);
    const $xhr = $.getJSON('https://cah.greencoaststudios.com/api/v1/        ', setPack);
    return function abort() {
      $xhr.abort();
    }
  }, []);

  //setWhiteCards(pack.white);
  //setBlackCards(pack.black);

  return (
      <div>
        <p>{pack ? "no": "yes"}</p>
        <p>white cards:</p>
        <p>black cards:</p>
      </div>
  );
});
从'react router dom'导入{Link,withRouter};
从“react”导入{useState,useEffect};
从“jquery”导入美元;
使用路由器导出默认值(函数游戏(){
const[pack,setPack]=useState(null);
const[blackCards,setBlackCards]=useState([]);
const[whiteCards,setWhiteCards]=useState([]);
useffect(函数(){
setPack(空);
const$xhr=$.getJSON('https://cah.greencoaststudios.com/api/v1/        ",setPack),;
返回函数中止(){
$xhr.abort();
}
}, []);
//设置白卡(包装为白色);
//立根板(黑色包装);
返回(
{包装?“否”:“是”}

白卡:

黑卡:

); });
从 我没有得到任何数据和以下注释:

加载失败:请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:3000因此,不允许访问


我能做什么?

这不是您的代码有问题,而是您试图访问的服务器有限制。如响应所示,服务器不允许跨源访问

我能做什么


基本上什么都没有,除了要求API开发人员将您的域(live,而不是
localhost
)添加到允许的源,或者使用您自己的代理服务器。

这是否回答了您的问题?