I am integrating an API with my react login form, but I am getting Failed to load response data: No data found for a resource with given identifier even for the status code 200.
When I fired the API in postman everything was working fine but when I integrate it with my application it is showing error 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);
});
}
I have added the code where I am integrating the API, any help will be appreciated.
The Error SyntaxError: Unexpected end of input usually
comes from invalid json response.
Maybe Postman shows you the raw response as text.
You should check if the response is valid json with no syntax failurs.
Things to try:
headers object add the following: Accept': 'application/json'}