Ad

Shopify Not Executing JQuery (Geolocation Script)

- 1 answer

I'm trying to use a jQuery script to alter the contact page layout based on the user's location. It works as expected in JSbin, but when ported to Shopify it's simply not working.

There's nothing in the console to suggest there's a conflict.

Does anyone have any ideas why it's not working?

EDIT: updated snippet to working solution. The IP service being called did not allow HTTPS requests, I switched to a different one and now it is working on Shopify as intended.

<script>
    $(document).ready(function() {
      
    $.ajax({
      url: "https://freegeoip.app/json/",
  dataType: "jsonp",
  success: function(json) {
    if (json.country_code === "GB") {
        alert('you are in the UK'); 
  }
  }      
});
    });
  </script>

Ad

Answer

Based on the like and info provided in the comments, I was able to run the code in your site's context. The code is executing successfully, but your API provider is prohibiting the action that you're trying to do based on your subscription level. See the error, below.

enter image description here

The API docs say it a bit differently - The current subscription plan does not support this API endpoint.

Ad
source: stackoverflow.com
Ad