I am experiencing issues when trying to retrieve data from an API using JavaScript. The API works fine in Postman, but it is not functioning properly in JavaScript.
When I run the code, the console displays an error message stating "Failed to fetch response data" and shows 'undefined':
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2> Only Fetch API </h2>
<script>
fetch('https://smweb.in/hungaroo/app/api/plan_list', {
method: 'POST',
mode: 'no-cors',
redirect: 'follow',
headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
}
})
.then(function (response) {
return response.text();
})
.then(function(data) {
console.log(data);
})
</script>
</body>
</html>