try 将symfony API与Reaction应用程序连接时,存在API拒绝返回任何响应的问题.但是,直接访问API链接时,返回的响应正确.

ApiDirectURL

但是,try 通过Reaction应用程序获取此数据不会返回任何内容.

  const api_url = "http://127.0.0.1:8000/app-api/";
  const farmid = "1234567890123456789012345678901234567890";
  
  async function getFarmInfo() {
    const response = await fetch(api_url + farmid + "/info",{
      cache: "no-store", 
      mode: "no-cors",
      method: "GET",
      headers: {
        "Accept": "application/json"
      }});
    const jsonData = await response.json();
    console.log(jsonData);
  }

ServerResponse

未响应API代码

   #[Route('/info', name: 'info')]
    public function info(Request $request,EntityManagerInterface $em,$fishingfarmid): Response
    {

        $farm = $em->getRepository(FishingFarm::class)->findOneBy(["trueId" => $fishingfarmid]);
        $json = ["phone" => $farm->getPhone() , "regulation" => $farm->getRegulations() , "email" => $farm->getEmail() , "address" => $farm->getAddress()];
        return new JsonResponse($json);
    }

然而,我意外地发现,如果我在某个地方使用var_ump("");函数,react 代码中的响应会突然出现.

#[Route('/info', name: 'info')]
public function info(Request $request,EntityManagerInterface $em,$fishingfarmid): Response
{

    $farm = $em->getRepository(FishingFarm::class)->findOneBy(["trueId" => $fishingfarmid]);
    $json = ["phone" => $farm->getPhone() , "regulation" => $farm->getRegulations() , "email" => $farm->getEmail() , "address" => $farm->getAddress()];
    var_dump("");
    return new JsonResponse($json);
}

百人赛的结果

Response with var_dump()

推荐答案

我不知道为什么,但go 掉mode: "no-cors"美元后它就能用了.

 async function getFarmInfo() {
    const response = await fetch(api_url + farmid + "/info",{
      method: "GET",
     });
    const jsonData = await response.json();
    
    setFarmInfo( jsonData);
  }

Javascript相关问答推荐

在卡信息之间切换

为什么JavaScript双边字符串文字插值不是二次的?

使用redux-toolet DelivercThunks刷新访问令牌

我在这个黑暗模式按钮上做错了什么?

如何使用侧边滚动按钮具体滚动每4个格?

Cypress -使用commands.js将数据测试id串在一起失败,但在将它们串在一起时不使用命令有效

硬币兑换运行超时

更改JSON中使用AJAX返回的图像的路径

如何从html元素创建树 struct ?

CheckBox作为Vue3中的一个组件

阿波罗返回的数据错误,但在网络判断器中是正确的

编剧如何获得一个div内的所有链接,然后判断每个链接是否都会得到200?

编辑文本无响应.onClick(扩展脚本)

如何将多维数组插入到另一个多维数组中?

有条件重定向到移动子域

在数组中查找重叠对象并仅返回那些重叠对象

从另一个数组中的对应行/键值对更新数组中的键值对对象

OpenAI转录API错误请求

按下单键和多值

如何在FiRestore中的事务中使用getCountFromServer