Blocked by CORS policy on Ajax

New Member
4 0 0

Hi Team,

I am trying to add the product outside the Shopify with ajax as follows -

 $.ajax({url: "{varient_id}", success: function(result){


But I am getting a "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource" error.

I am listing the product outside Shopify and then with the ajax I want to add the product to the respective user's cart.

With the permalink (ex -{varient_id} ) it is working but the page is redirecting and I don't want page redirection/reload hence use of ajax call it's giving the above error.


Is there any solution to this?

Reply 1 (1)
Shopify Partner
81 19 32

Hello @carat, Below snippet worked for me for this case

      url: $shop_url + '/cart/add.json?quantity=' + $quantity +'&id=' + $variant_id +'&callback=?', 
      success: function(data){ 
        /* do something with the data. */


Note:  $shop_url, $quantity and $variant_id are variables.