我尝试将 isomorphic-fetch
与带有 redux-thunk
中间件的 reactjs
应用程序一起使用。但是当我这样做时,我不断收到那些 Unexpected end of input error
let config = {
method: 'POST',
headers: { 'Content-Type':'application/x-www-form-urlencoded' },
mode: 'no-cors',
body: "username=foo&password=bar"
};
fetch('my_url', config)
.then(response => {
response.json().then(user => ({user, response})) // here is where the error always been thrown
})
即使服务器返回类似 {"user": "happy tree friends"}
的内容。
我使用此模块的方式是否有任何问题,或者我的服务器只是返回了错误的 JSON 数据。
求助!!!
最佳答案
也许你的 API,返回 empty
所以你得到错误
JSON.parse('')
将抛出 Uncaught SyntaxError: Unexpected end of input
关于javascript - `isomorphic-fetch` response.json() 方法总是抛出 Unexpected end of input 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419414/