Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hi Team,
I am trying to add the product outside the Shopify with ajax as follows -
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 -https://storename.myshopify.com/cart/add?id={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?
Hello @carat, Below snippet worked for me for this case
$.ajax({
dataType:'jsonp',
url: $shop_url + '/cart/add.json?quantity=' + $quantity +'&id=' + $variant_id +'&callback=?',
success: function(data){
/* do something with the data. */
//console.log(data.responseJSON);
}
});
Note: $shop_url, $quantity and $variant_id are variables.