Can';t使用redux saga从服务器生成json响应

Can';t使用redux saga从服务器生成json响应,redux,redux-saga,Redux,Redux Saga,我正在尝试使用stack react redux和redux传奇,并了解所需的最小管道 我做了一次github回购来重现我得到的错误: 运行应用程序:npm运行应用程序 网址: 该应用程序由一个简单的组合框和一个按钮组成。 从组合中选择一个值后,单击按钮分派一个操作,该操作只包括获取一些json数据。 服务器接收到正确的请求(基于所选的值),但行let json=yield call([res,'json'])。我得到了一个错误: 我从浏览器获得的错误消息: index.js:2177 un

我正在尝试使用stack react redux和redux传奇,并了解所需的最小管道

我做了一次github回购来重现我得到的错误:

  • 运行应用程序:npm运行应用程序
  • 网址:
  • 该应用程序由一个简单的组合框和一个按钮组成。 从组合中选择一个值后,单击按钮分派一个操作,该操作只包括获取一些json数据。 服务器接收到正确的请求(基于所选的值),但行let json=yield call([res,'json'])。我得到了一个错误:

    我从浏览器获得的错误消息:

     index.js:2177 uncaught at equipments at equipments 
       at takeEvery 
       at _callee 
     SyntaxError: Unexpected end of input
     at runCallEffect (http://localhost:3000/static/js/bundle.js:59337:19)
     at runEffect (http://localhost:3000/static/js/bundle.js:59259:648)
     at next (http://localhost:3000/static/js/bundle.js:59139:9)
     at currCb (http://localhost:3000/static/js/bundle.js:59212:7)
     at <anonymous>
    
    我在水管方面做错了什么,但我找不到地方

    非常感谢你的帮助


    Kasra

    redux saga
    的观点来看,所有代码都稍微正确-两个承诺都是通过
    调用
    效果顺序执行的

    let res  =  yield call(fetch,fetch_url, {mode: 'no-cors'})
    let json =  yield call([res, 'json']) 
    
    但是在
    no cors
    模式下使用
    fetch
    ,意味着响应体将无法从程序代码中获得,因为请求模式是
    不透明的


    如果您想从不同的来源获取信息,请使用带有适当HTTP头的
    cors
    模式,如
    Access Control Allow origin
    ,更多信息请参见此处:

    只是调用
    .json()
    的另一种方法,而不使用
    调用
    方法

    let res  =  yield call(fetch,fetch_url, {mode: 'no-cors'})
    
    // instead of const json =  yield call([res, res.json]);
    let json =  yield res.json();
    
    console.log(json)
    

    很可能与响应结果不是JSON格式有关。尝试
    yield call([res,'text'])
    看看结果到底是什么样子。(或查看您的网络选项卡)嗨,谢谢您的提示。我检查了网络以查看响应的内容类型,并且确实收到了application/json。我刚刚使用了then yield调用([res,'text']),它没有错误地传递了,但是console.log(json)是空的,即使我有一个responseAnks!!这就是我问题的解决办法;-)。我刚刚添加了res.setHeader('Access-Control-Allow-Origin',');在服务器上,它通过了。。。。。当然,在客户机上,正如您所说:let res=yield call(fetch,fetch_url,{mode:'cors})
    let res  =  yield call(fetch,fetch_url, {mode: 'no-cors'})
    
    // instead of const json =  yield call([res, res.json]);
    let json =  yield res.json();
    
    console.log(json)