I am getting this error when trying to send post request using my localhost api :
Access to fetch at 'http://127.0.0.1:8000/my-api/' from origin 'http://localhost:3000' has been blocked by CORS policy: 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.
here is my code:
const SubmitContact = async (e)=>{
e.preventDefault()
const contact = {contact_name,contact_email,contact_body}
fetch("http://127.0.0.1:8000/my-api/",{
method: "POST",
header: {
"Accept": "application/json",
"Content Type": "application/json",
},
body: JSON.stringify(contact)
}).then((result)=>{
console.warn(result)
})
}
Why I can't send post request where I am doing mistake? my api also working in post man so I think I might be doing any mistake in my javascript code.