Suddenly getting a Access-Control-Allow-Origin error when hitting the Shopify CDN from shop

Shopify Expert
50 0 3

So I've got a currency switcher on the bottom of this site that I built several months ago.

As part of the selector, it calls in a JSON file from the CDN to populate a dropdown containing a whole bunch of countries and currencies.

It worked perfectly for months. No one has touched it when suddenly a couple weeks ago it stopped working.

Here's the error I'm getting:

XMLHttpRequest cannot load http://cdn.shopify.com/s/files/1/0240/0795/t/2/assets/countries-currencies-json.js?6132. Origin http://www.teski.com is not allowed by Access-Control-Allow-Origin. 

Did Shopify turn off Access-Control-Allow-Origin for the CDN? I really can't imagine this is the issue or there'd have been more concern expressed already (although I did find this guy). Or maybe I'm asking the wrong question? Ultimately my question is - how do I get this to start working again. :)

Here's the code:

$.getJSON("{{ 'countries-currencies-json.js' | asset_url }}", function (jsonData) {
  $.each(jsonData, function (i, j) {
      // document.currencyform.country.options[i] = new Option(j.name, j.code, GetCountryCode() );
      $('#country').append('<option value=' + j.code + ' data-currency=' + j.currency + '>' + j.symbol + ' / ' + j.name + '</option>')
  });

 

0 Likes
Shopify Expert
3994 14 321

Is your JSON payload a static asset or does it change due to some whims? I am curious why you'd do an Ajax callback to get a JSON data structure that probably does not change much. A currency exchange would have to be real-time, but a simple code=US or code=UK etc... does not need Ajax... I am curious. Since you're not using JSONP in your request, and since your shop's domain differs from the CDN domain, it is seemingly correct to get this error. How did it ever work in the first place is then another question. You cannot do cross-domain Ajax without CORS setup or limiting yourself to JSONP.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Shopify Expert
50 0 3

Easier to manage this way, modular etc. Curious why it would stop working though - any ideas on that?

0 Likes
Shopify Expert
3994 14 321

How is doing a GET request to a file you placed on the CDN easier to manage and more modular than just rendering that data file right into your script?

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes