Most likely there is a problem with Cross-Origin Resource Sharing (CORS).
Have a read at https://www.twilio.com/blog/handling-cross-origin-resource-sharing-cors-requests-laravel-7 That should give you some guidance on what to fix.
Hello,
I have this problem.
If I run this code step by step with the debuger, all works fine.
But if I run this code normally, I get this error.
TypeError: NetworkError when attempting to fetch resource.
I think that it can be a problem with synchon / asynchron function, but I already have a promise.
const apiUrl = 'http://localhost:5678/api/students';
fetch(apiUrl, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
},
body: data,
}).then((res) => {
if (res.ok) {
console.log('success');
} else {
throw new Error('Error status code: ' + res.status);
}
}).catch((error) => {
console.log(error);
});
What could be the source of the problem ?
Thanks for your help.
V
Please or to participate in this conversation.