So I have for now a simple php file that looks like that:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS, PUT');
header("Access-Control-Allow-Headers: *");
echo 'test';
And I’m trying to call it from a SvelteKit form just like that:
<form
action="http://the.ip.adress:16000/add"
method="post"
enctype="multipart/form-data"
use:enhance={() => {
return async ({ result }) => {
console.log(result);
if (result.type === 'success') {
alert('Fichier ajoutée avec succès');
}
};
}}
>
</form>
I am calling it from localhost to a specific IP adress, but everytime I call it, it returns this error:
Access to fetch at 'http://the.ip.adress:16000/add' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
And when I check the network tab, it sends two request, one fail and doesn’t returns headers and the other succeed with the headers returned.