jquery - Ajax and Shopify Cart -
i'm using shopify , i'm trying add item cart using ajax. code here not add , item cart. i've spent 5 hours trying fix this, no cigar :/
i've included wrappers in in theme.liquid.
here's code:
<a class="chicken-fingers" onclick="fastcart('515257513','1')">add cart</a> <script> function fastcart(variantid, quantity){ $.ajax({ type: 'post', url: 'http://name.myshopify.com/cart/add.js', data: 'quantity='+quantity+'&id='+variantid, datatype: 'json', success: function(response){ $.ajax({ type: 'get', url: '/cart.js', datatype: 'json', success: function(cartdata){ $('.cart-total-items .count').html(cartdata.item_count); $('.cart-total-price').html('$'+(cartdata.total_price/100).tofixed(2)); } }); } }); } </script>
that not going work.
cross-domain ajax requests don't work , not allowed. can send requests own domain name, , cannot send ajax requests domain.
you can try out htmlagilitypack if you're using asp.net!
actually /cart/add.js
means move point own website's folder cart
, file of add.js
. way add component! in method, origin same, request made through website , sent website of yours.
if want save data on website, need use http post request data. , coding thing there, , come response! or use plugin this.
here main articles cross-domain tutorials:
https://en.wikipedia.org/wiki/cross-origin_resource_sharing
http://www.codeproject.com/articles/185506/ajax-cross-origin-http-request (these guys much)
https://en.wikipedia.org/wiki/same-origin_policy (learn here, requests allowed , fail)
Comments
Post a Comment