cancel
Showing results for 
Search instead for 
Did you mean: 

Angular Accept.js CORS error

I am using Angular 7 and have to add the accept.js script dynamically with the following:

const node = document.createElement('script');
node.src = 'https://apitest.authorize.net/xml/v1/request.api';
node.type = 'text/javascript';
node.charset = 'utf-8';
document.getElementsByTagName('head')[0].appendChild(node);

When I run 

Accept.dispatchData(secureData, (acceptResponse: any) => {
console.log(acceptResponse);
}

I get the error  Access to XMLHttpRequest at 'https://apitest.authorize.net/xml/v1/request.api' from origin 'https://localhost:8443' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
POST https://apitest.authorize.net/xml/v1/request.api net::ERR_FAILED

 

This error only occurs when the Accept.js script is cached. If I clear the browser cache and dispatchData again, the CORS error doesn't occur.

 

Why does caching the script in Angular cause this error, and what can I do to stop it?

mchaffins7
Member
0 REPLIES 0