SummerDays SummerDays - 4 months ago 23
Javascript Question

Linking an external JS library and getting XMLHttpRequest error

I need to use a JavaScript library and have it referenced as such:

<script type="text/javascript" src="https://js.authorize.net/v1/Accept.js"></script>


However I get an error that states:


XMLHttpRequest cannot load https://js.authorize.net/v1/AcceptCore.js.
No 'Access-Control-Allow-Origin' header is present on the requested
resource.


I've researched this issue and tried various bits of code and ideas, but it hasn't worked for me. I am using ASP.NET, webforms, and c#. I've tried adding various code to my web.config, such as

<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
</customHeaders>
</httpProtocol>
</system.webServer>


and

<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>


I also tried the recommendation of installing Cors, but I am using framework 4.0. Cors requires 5.0 and failed to install.

Answer

The script you're loading is just turning right around and using XMLHttpRequest to load another one (also from js.authorize.net); that request is being denied because your page's origin isn't allowed access. Looks like some kind of authorization thing to keep their JS from being downloaded on unauthorized origins.

Nothing you do on your end changes the CORS rules at the js.authorize.net end. It's that server, js.authorize.net, that has to allow your origin to do the request.

You'll need to work with the people behind js.authorize.net in order to get access.