I am using fetch function for ajax request but getting CORS error when i send the Ajax request. Anybody know how to fix this issue? I am unable to fix it. I would appreciate your help.
Access to fetch at ‘https://gatewayt.moneris.com/chkt/request/request.php’ from origin ‘https://www.test.com’ 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.
export function payToMoneris(orderData){
return fetch("https://gatewayt.moneris.com/chkt/request/request.php", {
method: 'POST',
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
},
body: JSON.stringify(checkout)
}).then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} );
}