I am trying to fetch data from API using JavaScript and this API is working in Postman but not working in JavaScript.
This code show in console as failed to fetch response data and 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>