Getting Cart content via /cart.js

Highlighted
Shopify Expert
27 0 14

I can add and update cart items just fine via the Shopify Ajax API but when I try to get cart contents via the below calls:

jQuery.get('/cart.js') or jQuery.getJSON('/cart.js')

The only response I ever get is:

{"readyState":1}

From the documention, this should be returning the full cart in JSON format (starting with token).

https://help.shopify.com/themes/development/getting-started/using-ajax-api#get-cart

Anyone have ideas on what I'm doing wrong?

0 Likes
Shopify Expert
27 0 14

In case anyone needs this. I was able to get access to the cart like so:

jQuery.getJSON('/cart.js', function(cart) {
   // now have access to Shopify cart object
   alert('There are now ' + cart.item_count + ' items in the cart.');
} );

 

6 Likes