【发布时间】:2021-10-14 17:27:07
【问题描述】:
我正在将 API 与我的 react 登录表单集成,但我收到 Failed to load response data: No data found for a resource with given identifier 即使状态码为 200。
当我在 postman 中触发 API 时,一切正常,但是当我将它与我的应用程序集成时,它显示错误 index.js:1 Error: SyntaxError: Unexpected end of input
let userLogIn = async function() {
fetch('http://kishansharma.pythonanywhere.com/login', {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `email=${emailId}&password=${password}`,
})
.then(response => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
我已在集成 API 的地方添加了代码,我们将不胜感激。
【问题讨论】:
-
能否请您添加沙箱或代码盘,以便在其上轻松找到错误。谢谢
-
@sedhalsoni 这是沙盒链接:codesandbox.io/s/cranky-forest-y3g9n?file=/src/App.js
-
@harsh 我在 200 OK 和 null 响应正文中也遇到了这个错误 - 尝试将新表 api 添加到我的应用程序时。数据库表字段名称与我的客户端模型或服务器模型不匹配。我在 db 表中使用了下划线,但在应用程序模型中使用了破折号。此外,应用模型中有一个属性缺少属性。服务器模型中的 RowVersion 应该有 [Timestamp] 属性和类型 byte[],而客户端模型是 Uint8Array。
标签: javascript reactjs json api fetch-api