API 即使状态 200 在反应中也没有获取任何响应(获取 API)

API not fetching any response even for status 200 in react(Fetch API)

我正在将 API 与我的 React 登录表单集成,但我得到 无法加载响应数据:没有找到具有给定标识符 的资源的数据对于状态代码 200。

当我在 postman 中触发 API 时,一切正常,但是当我将它与我的应用程序集成时,它显示错误 index.js:1 错误:语法错误:意外结束输入

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 的地方添加了代码,我们将不胜感激。

错误 SyntaxError: Unexpected end of input 通常 来自无效的 json 响应。 也许 Postman 会将原始响应显示为文本。 您应该检查响应是否有效 json 且没有语法错误。

要尝试的事情:

  • 在您的 headers 对象中添加以下内容:Accept': 'application/json'
  • 回复是否真的有效JSON?有时会缺少 }